Correctly send message, level and hostname

Fix issue #230 where the level would hold the message and the log level
information would be lost.
This commit is contained in:
Grégoire Charvet 黑瓜
2014-08-18 07:25:55 +08:00
parent d65d053bc1
commit e7267ecf46
+11 -17
View File
@@ -18,24 +18,18 @@ var layouts = require('../layouts')
*/ */
function logglyAppender(config, layout) { function logglyAppender(config, layout) {
var client = loggly.createClient(config); var client = loggly.createClient(config);
if(!layout) layout = passThrough;
function packageMessage(loggingEvent) { return function(loggingEvent) {
function BaseItem(level, msg) { console.log('logging ', loggingEvent);
this.level = level || loggingEvent.level.toString(); var msg = layout(loggingEvent);
this.category = loggingEvent.categoryName; client.log({
this.hostname = os.hostname().toString(); msg: msg,
if (typeof msg !== 'undefined') level: loggingEvent.level.levelStr,
this.msg = msg; category: loggingEvent.categoryName,
}; hostname: os.hostname().toString(),
});
var formattedMsg = passThrough(loggingEvent); }
return new BaseItem(formattedMsg);
};
return function(loggingEvent) {
var a = layout ? layout(loggingEvent) : packageMessage(loggingEvent);
client.log(a, config.tags);
};
} }
function configure(config) { function configure(config) {