2014-01-11 04:18:16 +08:00
|
|
|
"use strict";
|
2014-01-16 23:39:45 +08:00
|
|
|
var vows = require('vows')
|
|
|
|
, assert = require('assert')
|
|
|
|
, log4js = require('../lib/log4js')
|
|
|
|
, sandbox = require('sandboxed-module')
|
|
|
|
;
|
2014-01-11 04:18:16 +08:00
|
|
|
|
2014-01-16 23:39:45 +08:00
|
|
|
function setupLogging(category, options) {
|
|
|
|
var msgs = [];
|
|
|
|
|
|
|
|
var fakeLoggly = {
|
|
|
|
createClient: function (options) {
|
|
|
|
return {
|
|
|
|
config: options,
|
|
|
|
log: function (msg, tags) {
|
|
|
|
msgs.push({
|
|
|
|
msg: msg,
|
|
|
|
tags: tags
|
|
|
|
});
|
2014-01-11 04:18:16 +08:00
|
|
|
}
|
2014-01-16 23:39:45 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
2014-01-11 04:18:16 +08:00
|
|
|
|
2014-01-16 23:39:45 +08:00
|
|
|
var fakeLayouts = {
|
|
|
|
layout: function(type, config) {
|
|
|
|
this.type = type;
|
|
|
|
this.config = config;
|
|
|
|
return log4js.layouts.messagePassThroughLayout;
|
2014-01-11 04:18:16 +08:00
|
|
|
},
|
2014-01-16 23:39:45 +08:00
|
|
|
basicLayout: log4js.layouts.basicLayout,
|
|
|
|
messagePassThroughLayout: log4js.layouts.messagePassThroughLayout
|
|
|
|
};
|
|
|
|
|
|
|
|
var fakeConsole = {
|
|
|
|
errors: [],
|
|
|
|
error: function(msg, value) {
|
|
|
|
this.errors.push({ msg: msg, value: value });
|
|
|
|
}
|
|
|
|
};
|
2014-01-11 04:18:16 +08:00
|
|
|
|
2014-01-16 23:39:45 +08:00
|
|
|
var logglyModule = sandbox.require('../lib/appenders/loggly', {
|
|
|
|
requires: {
|
|
|
|
'loggly': fakeLoggly,
|
|
|
|
'../layouts': fakeLayouts
|
|
|
|
},
|
|
|
|
globals: {
|
|
|
|
console: fakeConsole
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
log4js.addAppender(logglyModule.configure(options), category);
|
|
|
|
|
|
|
|
return {
|
|
|
|
logger: log4js.getLogger(category),
|
|
|
|
loggly: fakeLoggly,
|
|
|
|
layouts: fakeLayouts,
|
|
|
|
console: fakeConsole,
|
|
|
|
results: msgs
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
log4js.clearAppenders();
|
|
|
|
vows.describe('log4js logglyAppender').addBatch({
|
|
|
|
'minimal config': {
|
|
|
|
topic: function() {
|
|
|
|
var setup = setupLogging('loggly', {
|
|
|
|
token: 'your-really-long-input-token',
|
|
|
|
subdomain: 'your-subdomain',
|
|
|
|
tags: ['loggly-tag1', 'loggly-tag2', 'loggly-tagn']
|
|
|
|
});
|
|
|
|
|
2014-03-04 23:27:04 +08:00
|
|
|
setup.logger.log('trace', 'Log event #1');
|
2014-01-16 23:39:45 +08:00
|
|
|
return setup;
|
|
|
|
},
|
|
|
|
'there should be one message only': function (topic) {
|
|
|
|
//console.log('topic', topic);
|
|
|
|
assert.equal(topic.results.length, 1);
|
2014-01-11 04:18:16 +08:00
|
|
|
}
|
|
|
|
}
|
2014-01-16 23:39:45 +08:00
|
|
|
|
|
|
|
}).export(module);
|