@@ -76,8 +76,50 @@ vows.describe('log4js layouts').addBatch({
76
76
, toString : function ( ) { return "ERROR" ; }
77
77
}
78
78
} ) , "{ thing: 1 }" ) ;
79
+ } ,
80
+ 'should print the stacks of a passed error objects' : function ( layout ) {
81
+ assert . isArray ( layout ( {
82
+ data : [ new Error ( ) ]
83
+ , startTime : new Date ( 2010 , 11 , 5 , 14 , 18 , 30 , 45 )
84
+ , categoryName : "cheese"
85
+ , level : {
86
+ colour : "green"
87
+ , toString : function ( ) { return "ERROR" ; }
88
+ }
89
+ } ) . match ( / E r r o r \s + a t O b j e c t \. < a n o n y m o u s > \s + \( ( .* ) t e s t [ \\ \/ ] l a y o u t s - t e s t \. j s \: \d + \: \d + \) \s + a t r u n T e s t / )
90
+ , 'regexp did not return a match' ) ;
91
+ } ,
92
+ 'with passed augmented errors' :
93
+ { topic :
94
+ function ( layout ) {
95
+ var e = new Error ( "My Unique Error Message" ) ;
96
+ e . augmented = "My Unique attribute value"
97
+ e . augObj = { at1 : "at2" }
98
+ return layout ( {
99
+ data : [ e ]
100
+ , startTime : new Date ( 2010 , 11 , 5 , 14 , 18 , 30 , 45 )
101
+ , categoryName : "cheese"
102
+ , level : {
103
+ colour : "green"
104
+ , toString : function ( ) { return "ERROR" ; }
105
+ }
106
+ } ) ;
107
+ } ,
108
+ 'should print error the contained error message' : function ( layoutOutput ) {
109
+ var m = layoutOutput . match ( / \{ \[ E r r o r : M y U n i q u e E r r o r M e s s a g e \] / ) ;
110
+ assert . isArray ( m ) ;
111
+ } ,
112
+ 'should print error augmented string attributes' : function ( layoutOutput ) {
113
+ var m = layoutOutput . match ( / a u g m e n t e d : \s ' M y U n i q u e a t t r i b u t e v a l u e ' / ) ;
114
+ assert . isArray ( m ) ;
115
+ } ,
116
+ 'should print error augmented object attributes' : function ( layoutOutput ) {
117
+ var m = layoutOutput . match ( / a u g O b j : \s \{ a t 1 : ' a t 2 ' \} / ) ;
118
+ assert . isArray ( m ) ;
119
+ }
79
120
}
80
121
122
+
81
123
} ,
82
124
83
125
'basicLayout' : {
@@ -106,10 +148,11 @@ vows.describe('log4js layouts').addBatch({
106
148
output = layout ( event ) ;
107
149
lines = output . split ( / \n / ) ;
108
150
109
- assert . equal ( lines . length , stack . length ) ;
110
- assert . equal ( lines [ 0 ] , "[2010-12-05 14:18:30.045] [DEBUG] tests - this is a test Error: Some made-up error" ) ;
151
+ assert . equal ( lines . length - 1 , stack . length ) ;
152
+ assert . equal ( lines [ 0 ] , "[2010-12-05 14:18:30.045] [DEBUG] tests - this is a test [Error: Some made-up error]" ) ;
153
+
111
154
for ( var i = 1 ; i < stack . length ; i ++ ) {
112
- assert . equal ( lines [ i + 1 ] , stack [ i + 1 ] ) ;
155
+ assert . equal ( lines [ i + 2 ] , stack [ i + 1 ] ) ;
113
156
}
114
157
} ,
115
158
'should output any extra data in the log event as util.inspect strings' : function ( args ) {
0 commit comments