This repository was archived by the owner on Jun 21, 2023. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -75,6 +75,15 @@ const maxLevelWrite: pino.WriteFn = function(this: any, data: object): void {
7575 }
7676} ;
7777
78+ const initFormatters = ( options : CosmasOptions & { loggerName ?: string } ) => {
79+ const formatters : pino . LoggerOptions [ 'formatters' ] = { } ;
80+ if ( options . pretty || options . disableStackdriverFormat ) return formatters ;
81+ formatters . level = ( _label : string , level : number ) => {
82+ return { level, severity : PINO_TO_STACKDRIVER [ level ] || 'UNKNOWN' } ;
83+ } ;
84+ return formatters ;
85+ } ;
86+
7887const defaultLogger = ( options : CosmasOptions & { loggerName ?: string } = { } ) : Cosmas => {
7988 serializers . disablePaths ( options . disableFields ) ;
8089 serializers . enablePaths ( options . enableFields ) ;
@@ -91,13 +100,7 @@ const defaultLogger = (options: CosmasOptions & { loggerName?: string } = {}): C
91100 const messageKey = 'message' ; // best option for Google Stackdriver,
92101 const streams = initLoggerStreams ( defaultLevel , Object . assign ( { } , options , { messageKey } ) ) ;
93102
94- const formatters : pino . LoggerOptions [ 'formatters' ] = { } ;
95-
96- if ( ! options . pretty && ! options . disableStackdriverFormat ) {
97- formatters . level = ( _label : string , level : number ) => {
98- return { level, severity : PINO_TO_STACKDRIVER [ level ] || 'UNKNOWN' } ;
99- } ;
100- }
103+ const formatters = initFormatters ( options ) ;
101104
102105 options . ignoredHttpMethods = options . ignoredHttpMethods || [ 'OPTIONS' ] ;
103106 const logger = ( pino (
You can’t perform that action at this time.
0 commit comments