log4js-node-amqp
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -15,3 +15,6 @@ var log4js = require('log4js'); | ||
}, | ||
category: 'example' | ||
category: 'example', | ||
additionalInfo: { | ||
application: 'example application' | ||
} | ||
} | ||
@@ -18,0 +21,0 @@ ] |
@@ -6,3 +6,3 @@ "use strict"; | ||
function amqpAppender(options) { | ||
var _options = normalizeOptions(options, { | ||
var _options = setObjectDefaults(options, { | ||
connection: { | ||
@@ -26,3 +26,4 @@ url: "amqp://guest:guest@localhost:5672", | ||
sendInterval: 0, | ||
layout: log4js.layouts.messagePassThroughLayout | ||
layout: log4js.layouts.messagePassThroughLayout, | ||
additionalInfo: {} | ||
}); | ||
@@ -37,3 +38,3 @@ | ||
process.on('exit', function() { | ||
process.on('exit', function () { | ||
if (connection) { | ||
@@ -62,8 +63,12 @@ connection.end(); | ||
toLog = logEventBuffer.shift(); | ||
exchange.publish(_options.publish.routingKey, { | ||
timestamp: toLog.startTime, | ||
data: toLog.data, | ||
level: toLog.level, | ||
category: toLog.logger.category | ||
}, _options.publish); | ||
exchange.publish( | ||
_options.publish.routingKey, | ||
setObjectDefaults({ | ||
timestamp: toLog.startTime, | ||
data: toLog.data, | ||
level: toLog.level, | ||
category: toLog.logger.category | ||
}, _options.additionalInfo), | ||
_options.publish | ||
); | ||
} | ||
@@ -84,3 +89,3 @@ } | ||
function normalizeOptions(obj, defaults) { | ||
function setObjectDefaults(obj, defaults) { | ||
obj = obj || {}; | ||
@@ -94,3 +99,3 @@ | ||
if (Object.prototype.toString.call(obj[key]) === '[object Object]') { | ||
return normalizeOptions(obj[key], defaults[key]); | ||
return setObjectDefaults(obj[key], defaults[key]); | ||
} else { | ||
@@ -104,3 +109,3 @@ obj[key] = obj[key]; | ||
return function (loggingEvent) { | ||
if(Object.prototype.toString.call(loggingEvent.data[0]) === '[object String]') { | ||
if (Object.prototype.toString.call(loggingEvent.data[0]) === '[object String]') { | ||
loggingEvent.data = _options.layout(loggingEvent); | ||
@@ -107,0 +112,0 @@ } else if (loggingEvent.data.length === 1) { |
{ | ||
"name": "log4js-node-amqp", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "An AMQP appender for log4js-node", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -17,2 +17,7 @@ log4js-node-amqp | ||
url: "amqp://guest:guest@localhost:5672" | ||
}, | ||
// this is a space for you to add custom bits to every log message | ||
additonalInfo: { | ||
machine: require("os").hostname(), | ||
applicationName: 'example application' | ||
} | ||
@@ -35,2 +40,7 @@ }), | ||
}, | ||
// this is a space for you to add custom bits to every log message | ||
additonalInfo: { | ||
machine: require("os").hostname(), | ||
applicationName: 'example application' | ||
} | ||
category: 'amqp-example' | ||
@@ -77,3 +87,7 @@ } | ||
// a log4js layout, this is ignored if the logged item is an object | ||
layout: log4js.layouts.messagePassThroughLayout | ||
layout: log4js.layouts.messagePassThroughLayout, | ||
// this is a space for you to add custom bits to every log message | ||
additonalInfo: { | ||
// | ||
} | ||
} | ||
@@ -84,3 +98,3 @@ | ||
```javascript | ||
// Everything log4js provides | ||
// Everything log4js provides, + whatever you added to additonalInfo (keys in additonalInfo are added as keys to the log message). | ||
{ | ||
@@ -96,2 +110,2 @@ timestamp: Fri Dec 20 2013 20:54:22 GMT-0800 (PST), | ||
Copyright (c) 2013 Max Nachlinger | ||
Copyright (c) 2014 Max Nachlinger |
@@ -195,2 +195,42 @@ "use strict"; | ||
test("additionalInfo is logged when present", function(t) { | ||
var message = 'test-message'; | ||
var fakeAmqp = new FakeAmqp(); | ||
t.test("Setup", function(t) { | ||
log4js.clearAppenders(); | ||
mockery.registerMock('amqp', { | ||
createConnection: function () { | ||
fakeAmqp.connect(); | ||
return fakeAmqp; | ||
} | ||
}); | ||
t.end(); | ||
}); | ||
t.test(function (t) { | ||
var applicationName = 'test-application-name'; | ||
var index = require('../lib/index'); | ||
log4js.addAppender(index.configure({ | ||
additionalInfo: { | ||
applicationName: applicationName | ||
} | ||
}), 'test'); | ||
fakeAmqp.setupCb = function() { | ||
log4js.getLogger('test').info(message); | ||
t.equal(fakeAmqp.messages.length, 1, "one message was sent: " + util.inspect(fakeAmqp.messages)); | ||
t.equal(fakeAmqp.messages[0].applicationName, applicationName, "applicationName '" + applicationName + "' was sent"); | ||
t.end(); | ||
}; | ||
}); | ||
t.test("Teardown", function (t) { | ||
mockery.deregisterAll(); | ||
mockery.resetCache(); | ||
t.end(); | ||
}); | ||
}); | ||
test("Teardown", function (t) { | ||
@@ -197,0 +237,0 @@ mockery.disable(); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12697
338
107