@@ -327,6 +327,55 @@ vows.describe('log4js').addBatch({
327
327
}
328
328
} ,
329
329
330
+ 'basicLayout' : {
331
+ topic : function ( ) {
332
+ var layout = require ( '../lib/log4js' ) ( ) . basicLayout ,
333
+ event = {
334
+ message : 'this is a test' ,
335
+ startTime : new Date ( 2010 , 11 , 5 , 14 , 18 , 30 , 45 ) ,
336
+ categoryName : "tests" ,
337
+ level : {
338
+ colour : "green" ,
339
+ toString : function ( ) { return "DEBUG" ; }
340
+ }
341
+ } ;
342
+ return [ layout , event ] ;
343
+ } ,
344
+ 'should take a logevent and output a formatted string' : function ( args ) {
345
+ var layout = args [ 0 ] , event = args [ 1 ] ;
346
+ assert . equal ( layout ( event ) , "[2010-12-05 14:18:30.045] [DEBUG] tests - this is a test" ) ;
347
+ } ,
348
+ 'should output a stacktrace, message if the event has an error attached' : function ( args ) {
349
+ var layout = args [ 0 ] , event = args [ 1 ] , output , lines ,
350
+ error = new Error ( "Some made-up error" ) ,
351
+ stack = error . stack . split ( / \n / ) ;
352
+
353
+ event . exception = error ;
354
+ output = layout ( event ) ;
355
+ lines = output . split ( / \n / ) ;
356
+
357
+ assert . length ( lines , stack . length + 1 ) ;
358
+ assert . equal ( lines [ 0 ] , "[2010-12-05 14:18:30.045] [DEBUG] tests - this is a test" ) ;
359
+ assert . equal ( lines [ 1 ] , "[2010-12-05 14:18:30.045] [DEBUG] tests - Error: Some made-up error" ) ;
360
+ for ( var i = 1 ; i < stack . length ; i ++ ) {
361
+ assert . equal ( lines [ i + 1 ] , stack [ i ] ) ;
362
+ }
363
+ } ,
364
+ 'should output a name and message if the event has something that pretends to be an error' : function ( args ) {
365
+ var layout = args [ 0 ] , event = args [ 1 ] , output , lines ;
366
+ event . exception = {
367
+ name : 'Cheese' ,
368
+ message : 'Gorgonzola smells.'
369
+ } ;
370
+ output = layout ( event ) ;
371
+ lines = output . split ( / \n / ) ;
372
+
373
+ assert . length ( lines , 2 ) ;
374
+ assert . equal ( lines [ 0 ] , "[2010-12-05 14:18:30.045] [DEBUG] tests - this is a test" ) ;
375
+ assert . equal ( lines [ 1 ] , "[2010
5A24
-12-05 14:18:30.045] [DEBUG] tests - Cheese: Gorgonzola smells." ) ;
376
+ }
377
+ } ,
378
+
330
379
'logLevelFilter' : {
331
380
topic : function ( ) {
332
381
var log4js = require ( '../lib/log4js' ) ( ) , logEvents = [ ] , logger ;
0 commit comments