@@ -120,6 +120,61 @@ describe('Logger', function() {
120120 expect ( logArguments . error_data . length ) . to . eql ( 3004 ) ;
121121 } ) ;
122122
123+ describe ( '#customError' , function ( ) {
124+ it ( 'should log error as the given severity with action' , function ( ) {
125+ const error = new Error ( 'failed' ) ;
126+ error . data = { test : 'data' } ;
127+
128+ logger . customError ( 'info' , 'hi' , error , { details : 'here' } ) ;
129+
130+ const logArguments = JSON . parse ( console . log . args [ 0 ] ) ;
131+ expect ( logArguments . name ) . to . eql ( 'mongo' ) ;
132+ expect ( logArguments . action ) . to . eql ( 'hi' ) ;
133+ expect ( logArguments . level ) . to . eql ( 30 ) ;
134+ expect ( logArguments . details ) . to . eql ( 'here' ) ;
135+
136+ expect ( logArguments . error_name ) . to . eql ( error . name ) ;
137+ expect ( logArguments . error_stack ) . to . eql ( error . stack ) ;
138+ expect ( logArguments . error_message ) . to . eql ( error . message ) ;
139+ expect ( logArguments . error_data ) . to . eql ( JSON . stringify ( error . data ) ) ;
140+ } ) ;
141+
142+ it ( 'should not log error data when it is undefined' , function ( ) {
143+ const error = new Error ( 'failed' ) ;
144+
145+ logger . customError ( 'warn' , 'hi' , error , { details : 'here' } ) ;
146+
147+ const logArguments = JSON . parse ( console . log . args [ 0 ] ) ;
148+ expect ( logArguments . name ) . to . eql ( 'mongo' ) ;
149+ expect ( logArguments . action ) . to . eql ( 'hi' ) ;
150+ expect ( logArguments . level ) . to . eql ( 40 ) ;
151+ expect ( logArguments . details ) . to . eql ( 'here' ) ;
152+
153+ expect ( logArguments . error_name ) . to . eql ( error . name ) ;
154+ expect ( logArguments . error_stack ) . to . eql ( error . stack ) ;
155+ expect ( logArguments . error_message ) . to . eql ( error . message ) ;
156+ expect ( logArguments ) . to . not . have . any . keys ( 'error_data' ) ;
157+ } ) ;
158+
159+ it ( 'should log only 3000 character of data' , function ( ) {
160+ const error = new Error ( 'failed' ) ;
161+ error . data = 'exactlyTen' . repeat ( 400 ) ;
162+
163+ logger . customError ( 'error' , 'hi' , error , { details : 'here' } ) ;
164+
165+ const logArguments = JSON . parse ( console . log . args [ 0 ] ) ;
166+ expect ( logArguments . name ) . to . eql ( 'mongo' ) ;
167+ expect ( logArguments . action ) . to . eql ( 'hi' ) ;
168+ expect ( logArguments . level ) . to . eql ( 50 ) ;
169+ expect ( logArguments . details ) . to . eql ( 'here' ) ;
170+
171+ expect ( logArguments . error_name ) . to . eql ( error . name ) ;
172+ expect ( logArguments . error_stack ) . to . eql ( error . stack ) ;
173+ expect ( logArguments . error_message ) . to . eql ( error . message ) ;
174+ expect ( logArguments . error_data . length ) . to . eql ( 3004 ) ;
175+ } ) ;
176+ } ) ;
177+
123178 describe ( '#configure' , function ( ) {
124179 it ( 'should change format method' , function ( ) {
125180 const formattedOutput = '{"my":"method"}' ;
0 commit comments