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

View File

@ -18,24 +18,18 @@ var layouts = require('../layouts')
*/
function logglyAppender(config, layout) {
var client = loggly.createClient(config);
if(!layout) layout = passThrough;
function packageMessage(loggingEvent) {
function BaseItem(level, msg) {
this.level = level || loggingEvent.level.toString();
this.category = loggingEvent.categoryName;
this.hostname = os.hostname().toString();
if (typeof msg !== 'undefined')
this.msg = msg;
};
var formattedMsg = passThrough(loggingEvent);
return new BaseItem(formattedMsg);
};
return function(loggingEvent) {
var a = layout ? layout(loggingEvent) : packageMessage(loggingEvent);
client.log(a, config.tags);
};
return function(loggingEvent) {
console.log('logging ', loggingEvent);
var msg = layout(loggingEvent);
client.log({
msg: msg,
level: loggingEvent.level.levelStr,
category: loggingEvent.categoryName,
hostname: os.hostname().toString(),
});
}
}
function configure(config) {