2 var vows = require('vows')
3 , assert = require('assert')
4 , log4js = require('../lib/log4js')
5 , sandbox = require('sandboxed-module')
8 function setupLogging(category, options) {
12 createClient: function(options) {
15 log: function(msg, tags) {
26 layout: function(type, config) {
29 return log4js.layouts.messagePassThroughLayout;
31 basicLayout: log4js.layouts.basicLayout,
32 messagePassThroughLayout: log4js.layouts.messagePassThroughLayout
37 error: function(msg, value) {
38 this.errors.push({ msg: msg, value: value });
42 var logglyModule = sandbox.require('../lib/appenders/loggly', {
45 '../layouts': fakeLayouts
52 log4js.addAppender(logglyModule.configure(options), category);
55 logger: log4js.getLogger(category),
63 log4js.clearAppenders();
65 function setupTaggedLogging() {
66 return setupLogging('loggly', {
67 token: 'your-really-long-input-token',
68 subdomain: 'your-subdomain',
69 tags: ['loggly-tag1', 'loggly-tag2', 'loggly-tagn']
73 vows.describe('log4js logglyAppender').addBatch({
74 'with minimal config': {
76 var setup = setupTaggedLogging();
77 setup.logger.log('trace', 'Log event #1', 'Log 2', { tags: ['tag1', 'tag2'] });
80 'has a results.length of 1': function(topic) {
81 assert.equal(topic.results.length, 1);
83 'has a result msg with both args concatenated': function(topic) {
84 assert.equal(topic.results[0].msg.msg, 'Log event #1 Log 2');
86 'has a result tags with the arg that contains tags': function(topic) {
87 assert.deepEqual(topic.results[0].tags, ['tag1', 'tag2']);
91 'config with object with tags and other keys': {
93 var setup = setupTaggedLogging();
95 // ignore this tags object b/c there are 2 keys
96 setup.logger.log('trace', 'Log event #1', { other: 'other', tags: ['tag1', 'tag2'] });
99 'has a results.length of 1': function(topic) {
100 assert.equal(topic.results.length, 1);
102 'has a result msg with the args concatenated': function(topic) {
103 assert.equal(topic.results[0].msg.msg,
104 'Log event #1 { other: \'other\', tags: [ \'tag1\', \'tag2\' ] }');
106 'has a result tags with the arg that contains no tags': function(topic) {
107 assert.deepEqual(topic.results[0].tags, []);