1
1
"use strict" ;
2
2
var vows = require ( 'vows' )
3
- , assert = require ( 'assert' )
4
- , log4js = require ( '../lib/log4js' )
5
- , sandbox = require ( 'sandboxed-module' )
6
- ;
3
+ , assert = require ( 'assert' )
4
+ , log4js = require ( '../lib/log4js' )
5
+ , sandbox = require ( 'sandboxed-module' )
6
+ ;
7
7
8
8
function setupLogging ( category , options ) {
9
9
var msgs = [ ] ;
10
-
10
+
11
11
var fakeLoggly = {
12
- createClient : function ( options ) {
12
+ createClient : function ( options ) {
13
13
return {
14
14
config : options ,
15
- log : function ( msg , tags ) {
15
+ log : function ( msg , tags ) {
16
16
msgs . push ( {
17
17
msg : msg ,
18
18
tags : tags
@@ -50,7 +50,7 @@ function setupLogging(category, options) {
50
50
} ) ;
51
51
52
52
log4js . addAppender ( logglyModule . configure ( options ) , category ) ;
53
-
53
+
54
54
return {
55
55
logger : log4js . getLogger ( category ) ,
56
56
loggly : fakeLoggly ,
@@ -61,22 +61,50 @@ function setupLogging(category, options) {
61
61
}
62
62
63
63
log4js . clearAppenders ( ) ;
64
+
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' ]
70
+ } ) ;
71
+ }
72
+
64
73
vows . describe ( 'log4js logglyAppender' ) . addBatch ( {
65
- 'minimal config' : {
74
+ 'with minimal config' : {
66
75
topic : function ( ) {
67
- var setup = setupLogging ( 'loggly' , {
68
- token : 'your-really-long-input-token' ,
69
- subdomain : 'your-subdomain' ,
70
- tags : [ 'loggly-tag1' , 'loggly-tag2' , 'loggly-tagn' ]
71
- } ) ;
72
-
73
- setup . logger . log ( 'trace' , 'Log event #1' ) ;
76
+ var setup = setupTaggedLogging ( ) ;
77
+ setup . logger . log ( 'trace' , 'Log event #1' , 'Log 2' , { tags : [ 'tag1' , 'tag2' ] } ) ;
74
78
return setup ;
75
79
} ,
76
- 'there should be one message only' : function ( topic ) {
77
- //console.log('topic', topic);
80
+ 'has a results.length of 1' : function ( topic ) {
78
81
assert . equal ( topic . results . length , 1 ) ;
82
+ } ,
83
+ 'has a result msg with both args concatenated' : function ( topic ) {
84
+ assert . equal ( topic . results [ 0 ] . msg . msg , 'Log event #1 Log 2' ) ;
85
+ } ,
86
+ 'has a result tags with the arg that contains tags' : function ( topic ) {
87
+ assert . deepEqual ( topic . results [ 0 ] . tags , [ 'tag1' , 'tag2' ] ) ;
79
88
}
80
89
}
90
+ } ) . addBatch ( {
91
+ 'config with object with tags and other keys' : {
92
+ topic : function ( ) {
93
+ var setup = setupTaggedLogging ( ) ;
81
94
95
+ // ignore this tags object b/c there are 2 keys
96
+ setup . logger . log ( 'trace' , 'Log event #1' , { other : 'other' , tags : [ 'tag1' , 'tag2' ] } ) ;
97
+ return setup ;
98
+ } ,
99
+ 'has a results.length of 1' : function ( topic ) {
100
+ assert . equal ( topic . results . length , 1 ) ;
101
+ } ,
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\' ] }' ) ;
105
+ } ,
106
+ 'has a result tags with the arg that contains no tags' : function ( topic ) {
107
+ assert . deepEqual ( topic . results [ 0 ] . tags , [ ] ) ;
108
+ }
109
+ }
82
110
} ) . export ( module ) ;
0 commit comments