First working version

tried examples/loggly-appender.js [OK]
This commit is contained in:
Christiaan Westerbeek 2014-01-10 21:51:08 +01:00
parent 5286c50375
commit eb51aa99be
2 changed files with 19 additions and 14 deletions

View File

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

View File

@ -1,6 +1,6 @@
"use strict"; "use strict";
var layouts = require("../layouts") var layouts = require("../layouts")
, mailer = require("loggly") , loggly = require("loggly")
, os = require('os'); , os = require('os');
@ -22,7 +22,14 @@ function logglyAppender(config, layout) {
return function(loggingEvent) { return function(loggingEvent) {
client.log(layout(loggingEvent)); 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));
}
});
}; };
} }
@ -35,6 +42,6 @@ function configure(config) {
return logglyAppender(config, layout); return logglyAppender(config, layout);
} }
exports.name = "loggly"; exports.name = "loggly";
exports.appender = logglyAppender; exports.appender = logglyAppender;
exports.configure = configure; exports.configure = configure;