@@ -522,19 +522,130 @@ describe.each(EACH_MATRIX)('%s:%s: integration tests', (eventSourceName, framewo
522522 // expect(customLogger.debug.mock.calls.length).toBe(0)
523523 } )
524524
525+ test ( 'custom levels' , ( ) => {
526+ const loggerError = serverlessExpressLogger ( { level : 'error' } )
527+
528+ loggerError . error ( 'error' )
529+ loggerError . info ( 'nocall' )
530+ loggerError . warn ( 'nocall' )
531+ loggerError . debug ( 'nocall' )
532+ loggerError . verbose ( 'nocall' )
533+ expect ( global . console . warn ) . not . toHaveBeenCalled ( )
534+ expect ( global . console . debug ) . not . toHaveBeenCalled ( )
535+ expect ( global . console . info ) . not . toHaveBeenCalled ( )
536+ expect ( global . console . error ) . toHaveBeenLastCalledWith ( {
537+ message : 'error'
538+ } )
539+
540+ const loggerWarn = serverlessExpressLogger ( { level : 'warn' } )
541+
542+ loggerWarn . error ( 'error2' )
543+ loggerWarn . warn ( 'warn2' )
544+ loggerWarn . info ( 'nocall' )
545+ loggerWarn . debug ( 'nocall' )
546+ loggerWarn . verbose ( 'nocall' )
547+ expect ( global . console . debug ) . not . toHaveBeenCalled ( )
548+ expect ( global . console . info ) . not . toHaveBeenCalled ( )
549+ expect ( global . console . error ) . toHaveBeenLastCalledWith ( {
550+ message : 'error2'
551+ } )
552+ expect ( global . console . warn ) . toHaveBeenLastCalledWith ( {
553+ message : 'warn2'
554+ } )
555+
556+ const loggerInfo = serverlessExpressLogger ( { level : 'info' } )
557+
558+ loggerInfo . error ( 'error3' )
559+ loggerInfo . warn ( 'warn3' )
560+ loggerInfo . info ( 'info3' )
561+ loggerInfo . debug ( 'nocall' )
562+ loggerInfo . verbose ( 'nocall' )
563+ expect ( global . console . debug ) . not . toHaveBeenCalled ( )
564+ expect ( global . console . error ) . toHaveBeenLastCalledWith ( {
565+ message : 'error3'
566+ } )
567+ expect ( global . console . warn ) . toHaveBeenLastCalledWith ( {
568+ message : 'warn3'
569+ } )
570+ expect ( global . console . info ) . toHaveBeenLastCalledWith ( {
571+ message : 'info3'
572+ } )
573+
574+ const loggerVerbose = serverlessExpressLogger ( { level : 'verbose' } )
575+
576+ loggerVerbose . error ( 'error4' )
577+ loggerVerbose . warn ( 'warn4' )
578+ loggerVerbose . info ( 'info4' )
579+ loggerVerbose . verbose ( 'verbose4' )
580+ loggerVerbose . debug ( 'nocall' )
581+ expect ( global . console . error ) . toHaveBeenLastCalledWith ( {
582+ message : 'error4'
583+ } )
584+ expect ( global . console . warn ) . toHaveBeenLastCalledWith ( {
585+ message : 'warn4'
586+ } )
587+ expect ( global . console . info ) . toHaveBeenLastCalledWith ( {
588+ message : 'info4'
589+ } )
590+ expect ( global . console . debug ) . toHaveBeenLastCalledWith ( {
591+ message : 'verbose4'
592+ } )
593+
594+ const loggerDebug = serverlessExpressLogger ( { level : 'debug' } )
595+
596+ loggerDebug . error ( 'error5' )
597+ loggerDebug . warn ( 'warn5' )
598+ loggerDebug . info ( 'info5' )
599+ loggerDebug . verbose ( 'verbose5' )
600+ loggerDebug . debug ( 'debug5' )
601+ expect ( global . console . error ) . toHaveBeenLastCalledWith ( {
602+ message : 'error5'
603+ } )
604+ expect ( global . console . warn ) . toHaveBeenLastCalledWith ( {
605+ message : 'warn5'
606+ } )
607+ expect ( global . console . info ) . toHaveBeenLastCalledWith ( {
608+ message : 'info5'
609+ } )
610+ expect ( global . console . debug ) . toHaveBeenLastCalledWith ( {
611+ message : 'debug5'
612+ } )
613+ } )
614+
525615 test ( 'lazy print of logger' , async ( ) => {
526- const logger = serverlessExpressLogger ( )
616+ const logger = serverlessExpressLogger ( { level : 'debug' } )
527617
618+ logger . debug ( 'simple message' )
528619 logger . debug ( 'debug' , ( ) => '=true' , ' works' )
529620 logger . debug ( ( ) => 'debug' )
621+ logger . debug ( 'array' , [ 'message' ] )
530622
531- expect ( global . console . debug ) . not . toHaveBeenNthCalledWith (
623+ expect ( global . console . debug ) . toHaveBeenNthCalledWith (
532624 1 ,
533- 'debug=true works'
625+ {
626+ message : 'simple message'
627+ }
534628 )
535- expect ( global . console . debug ) . not . toHaveBeenNthCalledWith (
629+ expect ( global . console . debug ) . toHaveBeenNthCalledWith (
536630 2 ,
537- 'debug'
631+ {
632+ message : 'debug' ,
633+ 0 : '=true' ,
634+ 1 : ' works'
635+ }
636+ )
637+ expect ( global . console . debug ) . toHaveBeenNthCalledWith (
638+ 3 ,
639+ {
640+ message : 'debug'
641+ }
642+ )
643+ expect ( global . console . debug ) . toHaveBeenNthCalledWith (
644+ 4 ,
645+ {
646+ message : 'array' ,
647+ 0 : [ 'message' ]
648+ }
538649 )
539650 } )
540651 } )
0 commit comments