[READ-ONLY] Mirror of https://github.com/FoxxMD/logging. A typed, opinionated, batteries-included, Pino-based logging solution for backend TS/JS projects foxxmd.github.io/logging
child-logger logging logging-library nodejs pinojs typescript-library
0

Configure Feed

Select the types of activity you want to include in your feed.

More convenience options for child logger filtering

FoxxMD (Feb 28, 2026, 2:34 AM UTC) 2fd94ec2 4e1b7cbd

+17 -2
+15
README.md
··· 205 205 const nestedChild2 = childLogger(nestedChild1, ['Second', 'Third'], { level: 'silent' }); 206 206 nestedChild2.info('I do not log because of set level and not enabled by filter'); 207 207 208 + // without LOG_FILTER_ENABLE from above set, the below logging would be silent 209 + // because they inherit the level from their parent 210 + 208 211 const nestedChild3 = childLogger(nestedChild2, ['Fourth']); 209 212 nestedChild3.info('I do log because of filter Third:Fourth'); 210 213 ··· 214 217 const nestedChild5 = childLogger(nestedChild4, ['Bar']); 215 218 nestedChild5.info('I do log because of filter Bar'); 216 219 ``` 220 + 221 + The minimum level a child logger is "enabled" to is ENV `LOG_FILTER_ENABLE_LEVEL` or `trace`, by default. It can also be specified by passing `labelEnableLevel` to childLogger options. 222 + 223 + The minimum level a child logger is "disabled" to is ENV `LOG_FILTER_DISABLE_LEVEL` or `silent`, by default. It can also be specified by passing `labelDisableLevel` to childLogger options. 224 + 225 + There are also options for passing your own function to determine if a child logger should be enabled or disabled. See [`childLogger`](https://foxxmd.github.io/logging/functions/index.childLogger.html) docs for full a full reference. 226 + 227 + A caveat to be aware of: **enable/disable by filter is evaluated once, when `childLogger` is instantiated.** This means: 228 + 229 + * Only the labels added by `childLogger` insantiation are applicable. Labels added during logging, IE `logger.info({labels: ['Runtime']}, "a log")`, are not considered. 230 + * Labels that are functions are evaluated **once**, when `childLogger` is instantiated 231 + * Changing the `LOG_FILTER_*` envs after a childLogger is created will have no effect on it 217 232 218 233 ### Serializing Objects and Errors 219 234
+2 -2
src/loggers.ts
··· 97 97 export const childLogger = (parent: Logger, labelsVal: any | any[] = [], context: object = {}, options: ChildLoggerOptions = {}): Logger => { 98 98 const { 99 99 labelEnable = labelsEnableFromEnvSingleton, 100 - labelEnableLevel = parent.level, 100 + labelEnableLevel = process.env.LOG_FILTER_ENABLE_LEVEL ?? 'trace', 101 101 labelDisable = labelsDisableFromEnvSingleton, 102 - labelDisableLevel = 'silent', 102 + labelDisableLevel = process.env.LOG_FILTER_DISABLE_LEVEL ?? 'silent', 103 103 ...rest 104 104 } = options; 105 105