@@ -4,9 +4,10 @@ assert = require('assert');
4
4
//used for patternLayout tests.
5
5
function test ( args , pattern , value ) {
6
6
var layout = args [ 0 ]
7
- , event = args [ 1 ] ;
7
+ , event = args [ 1 ]
8
+ , tokens = args [ 2 ] ;
8
9
9
- assert . equal ( layout ( pattern ) ( event ) , value ) ;
10
+ assert . equal ( layout ( pattern , tokens ) ( event ) , value ) ;
10
11
}
11
12
12
13
vows . describe ( 'log4js layouts' ) . addBatch ( {
@@ -175,8 +176,12 @@ vows.describe('log4js layouts').addBatch({
175
176
level : {
176
177
toString : function ( ) { return "DEBUG" ; }
177
178
}
178
- } , layout = require ( '../lib/layouts' ) . patternLayout ;
179
- return [ layout , event ] ;
179
+ } , layout = require ( '../lib/layouts' ) . patternLayout
180
+ , tokens = {
181
+ testString : 'testStringToken' ,
182
+ testFunction : function ( ) { return 'testFunctionToken' ; }
183
+ } ;
184
+ return [ layout , event , tokens ] ;
180
185
} ,
181
186
182
187
'should default to "time logLevel loggerName - message"' : function ( args ) {
@@ -246,6 +251,18 @@ vows.describe('log4js layouts').addBatch({
246
251
} ,
247
252
'%[%r%] should output colored time' : function ( args ) {
248
253
test ( args , '%[%r%]' , '\033[36m14:18:30\033[39m' ) ;
249
- }
254
+ } ,
255
+ '%x{testString} should output the string stored in tokens' : function ( args ) {
256
+ test ( args , '%x{testString}' , 'testStringToken' ) ;
257
+ } ,
258
+ '%x{testFunction} should output the result of the function stored in tokens' : function ( args ) {
259
+ test ( args , '%x{testFunction}' , 'testFunctionToken' ) ;
260
+ } ,
261
+ '%x{doesNotExist} should output the string stored in tokens' : function ( args ) {
262
+ test ( args , '%x{doesNotExist}' , '%x{doesNotExist}' ) ;
263
+ } ,
264
+ '%x should output the string stored in tokens' : function ( args ) {
265
+ test ( args , '%x' , '%x' ) ;
266
+ } ,
250
267
}
251
268
} ) . export ( module ) ;
0 commit comments