2014-01-21 19:11:32 +08:00
|
|
|
'use strict';
|
|
|
|
var layouts = require('../layouts')
|
|
|
|
, loggly = require('loggly')
|
2014-07-04 14:03:08 +08:00
|
|
|
, os = require('os')
|
|
|
|
, passThrough = layouts.messagePassThroughLayout;
|
|
|
|
|
2014-01-11 04:18:16 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Loggly Appender. Sends logging events to Loggly using node-loggly
|
|
|
|
*
|
|
|
|
* @param config object with loggly configuration data
|
|
|
|
* {
|
|
|
|
* token: 'your-really-long-input-token',
|
|
|
|
* subdomain: 'your-subdomain',
|
|
|
|
* tags: ['loggly-tag1', 'loggly-tag2', .., 'loggly-tagn']
|
|
|
|
* }
|
2014-01-21 19:11:32 +08:00
|
|
|
* @param layout a function that takes a logevent and returns a string (defaults to objectLayout).
|
2014-01-11 04:18:16 +08:00
|
|
|
*/
|
|
|
|
function logglyAppender(config, layout) {
|
|
|
|
var client = loggly.createClient(config);
|
2014-08-18 07:25:55 +08:00
|
|
|
if(!layout) layout = passThrough;
|
2014-01-21 19:11:32 +08:00
|
|
|
|
2014-08-18 07:25:55 +08:00
|
|
|
return function(loggingEvent) {
|
2014-08-18 07:31:33 +08:00
|
|
|
var msg = layout(loggingEvent);
|
|
|
|
client.log({
|
|
|
|
msg: msg,
|
|
|
|
level: loggingEvent.level.levelStr,
|
|
|
|
category: loggingEvent.categoryName,
|
|
|
|
hostname: os.hostname().toString(),
|
|
|
|
});
|
2014-08-18 07:25:55 +08:00
|
|
|
}
|
2014-01-11 04:18:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function configure(config) {
|
|
|
|
var layout;
|
|
|
|
if (config.layout) {
|
|
|
|
layout = layouts.layout(config.layout.type, config.layout);
|
|
|
|
}
|
|
|
|
return logglyAppender(config, layout);
|
|
|
|
}
|
|
|
|
|
2014-01-21 19:11:32 +08:00
|
|
|
exports.name = 'loggly';
|
2014-01-11 04:51:08 +08:00
|
|
|
exports.appender = logglyAppender;
|
2014-07-04 14:03:08 +08:00
|
|
|
exports.configure = configure;
|