2014-01-11 04:18:16 +08:00
|
|
|
"use strict";
|
|
|
|
var layouts = require("../layouts")
|
2014-01-11 04:51:08 +08:00
|
|
|
, loggly = require("loggly")
|
2014-01-11 04:18:16 +08:00
|
|
|
, os = require('os');
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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']
|
|
|
|
* }
|
|
|
|
* @param layout a function that takes a logevent and returns a string (defaults to basicLayout).
|
|
|
|
*/
|
|
|
|
function logglyAppender(config, layout) {
|
|
|
|
layout = layout || layouts.basicLayout;
|
|
|
|
|
|
|
|
var client = loggly.createClient(config);
|
|
|
|
|
|
|
|
|
|
|
|
return function(loggingEvent) {
|
2014-01-11 04:51:08 +08:00
|
|
|
console.log('attempts', loggingEvent, layout(loggingEvent), config.tags);
|
|
|
|
client.log(layout(loggingEvent), config.tags, function(err, result){
|
|
|
|
if (err) {
|
|
|
|
console.log('Loggly: '+ err.message);
|
|
|
|
} else {
|
|
|
|
console.log('Loggly: '+ JSON.stringify(result));
|
|
|
|
}
|
|
|
|
});
|
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-11 04:51:08 +08:00
|
|
|
exports.name = "loggly";
|
|
|
|
exports.appender = logglyAppender;
|
2014-01-11 04:18:16 +08:00
|
|
|
exports.configure = configure;
|