Added the basic files for Loggly appender

appender, example, test
not tested yet!
This commit is contained in:
Christiaan Westerbeek 2014-01-10 21:18:16 +01:00
parent bb644a1632
commit 5286c50375
3 changed files with 99 additions and 0 deletions

View File

@ -0,0 +1,26 @@
//Note that loggly appender needs node-loggly to work.
//If you haven't got node-loggly installed, you'll get cryptic
//"cannot find module" errors when using the loggly appender
var log4js = require('../lib/log4js')
, log
, logmailer
, i = 0;
log4js.configure({
"appenders": [
{
type: "console",
category: "test"
},
{
"type": "loggly",
"token": "12345678901234567890",
"subdomain": "your-subdomain",
"tags": ["test"],
"category": "test"
}
]
});
var logger = log4js.getLogger("test");
logger.info("Test log message");
logger.debug("Test log message");

40
lib/appenders/loggly.js Normal file
View File

@ -0,0 +1,40 @@
"use strict";
var layouts = require("../layouts")
, mailer = require("loggly")
, 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) {
client.log(layout(loggingEvent));
};
}
function configure(config) {
var layout;
if (config.layout) {
layout = layouts.layout(config.layout.type, config.layout);
}
return logglyAppender(config, layout);
}
exports.name = "loggly";
exports.appender = logglyAppender;
exports.configure = configure;

View File

@ -0,0 +1,33 @@
"use strict";
var assert = require('assert')
, vows = require('vows')
, layouts = require('../lib/layouts')
, sandbox = require('sandboxed-module');
vows.describe('../lib/appenders/loggly').addBatch({
'appender': {
topic: function() {
var messages = []
, fakeLoggly = {
log: function(msg) { messages.push(msg); }
}
, appenderModule = sandbox.require(
'../lib/appenders/loggly',
{
globals: {
'loggly': fakeLoggly
}
}
)
, appender = appenderModule.appender(layouts.messagePassThroughLayout);
appender({ data: ["blah"] });
return messages;
},
'should output to loggly': function(messages) {
assert.equal(messages[0], 'blah');
}
}
}).exportTo(module);