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