1- import { parseLogOptions } from "./funcs.js" ;
1+ import { labelsDisableFromEnv , labelsDisableFromEnvSingleton , labelsEnableFromEnv , labelsEnableFromEnvSingleton , parseLogOptions } from "./funcs.js" ;
22import {
33 PinoLoggerOptions ,
44 CUSTOM_LEVELS ,
55 Logger ,
66 LoggerAppExtras ,
77 LogLevel ,
88 LogLevelStreamEntry ,
9- LogOptions
9+ LogOptions ,
10+ ChildLoggerOptions
1011} from "./types.js" ;
1112import { buildDestinationFile , buildDestinationRollingFile , buildDestinationStdout } from "./destinations.js" ;
1213import { pino , levels , stdSerializers } from "pino" ;
@@ -45,7 +46,7 @@ export const buildLogger = (defaultLevel: LogLevel, streams: LogLevelStreamEntry
4546 } ,
4647 mixinMergeStrategy ( mergeObject : Record < any , any > , mixinObject : Record < any , any > ) {
4748 if ( mergeObject . labels === undefined || mixinObject . labels === undefined || mixinObject . labels . length === 0 ) {
48- return Object . assign ( mergeObject , mixinObject )
49+ return Object . assign ( mergeObject , mixinObject ) ;
4950 }
5051 const runtimeLabels = Array . isArray ( mergeObject . labels ) ? mergeObject . labels : [ mergeObject . labels ] ;
5152 const finalObj = Object . assign ( mergeObject , mixinObject ) ;
@@ -91,10 +92,18 @@ export const buildLogger = (defaultLevel: LogLevel, streams: LogLevelStreamEntry
9192 * @param parent Logger Parent logger to inherit from
9293 * @param labelsVal (any | any[]) Labels to always apply to logs from this logger
9394 * @param context object Additional properties to always apply to logs from this logger
94- * @param options object
95+ * @param options ChildLoggerOptions
9596 * */
96- export const childLogger = ( parent : Logger , labelsVal : any | any [ ] = [ ] , context : object = { } , options = { } ) : Logger => {
97- const newChild = parent . child ( context , options ) as Logger ;
97+ export const childLogger = ( parent : Logger , labelsVal : any | any [ ] = [ ] , context : object = { } , options : ChildLoggerOptions = { } ) : Logger => {
98+ const {
99+ labelEnable = labelsEnableFromEnvSingleton ,
100+ labelEnableLevel = parent . level ,
101+ labelDisable = labelsDisableFromEnvSingleton ,
102+ labelDisableLevel = 'silent' ,
103+ ...rest
104+ } = options ;
105+
106+ const newChild = parent . child ( context , rest ) as Logger ;
98107 const labels = Array . isArray ( labelsVal ) ? labelsVal : [ labelsVal ] ;
99108 newChild . labels = [ ...[ ...( parent . labels ?? [ ] ) ] , ...labels ] ;
100109 newChild . addLabel = function ( value ) {
@@ -103,6 +112,12 @@ export const childLogger = (parent: Logger, labelsVal: any | any[] = [], context
103112 }
104113 this . labels . push ( value ) ;
105114 }
115+
116+ if ( newChild . level !== labelEnableLevel && labelEnable !== undefined && labelEnable ( newChild . labels ) ) {
117+ newChild . level = labelEnableLevel ;
118+ } else if ( newChild . level !== labelDisableLevel && labelDisable !== undefined && labelDisable ( newChild . labels ) ) {
119+ newChild . level = labelDisableLevel ;
120+ }
106121 return newChild
107122}
108123/**
0 commit comments