[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.

feat: Enable passing additional pino options on loggerApp creation

FoxxMD (Mar 8, 2024, 2:49 PM EST) 772d05c0 3cc62b03

+21 -4
+4
README.md
··· 200 200 * Additional logging destinations to use alongside the built-in console/log stream. These can be any created by buildDestination* functions or other Pino Transports 201 201 * */ 202 202 destinations?: LogLevelStreamEntry[] 203 + /** 204 + * Additional Pino Log options that are passed to `pino()` on logger creation 205 + * */ 206 + pino?: PinoLoggerOptions 203 207 } 204 208 ``` 205 209
+7 -3
src/loggers.ts
··· 1 1 import {parseLogOptions} from "./funcs.js"; 2 2 import { 3 + PinoLoggerOptions, 3 4 CUSTOM_LEVELS, 4 5 Logger, 5 6 LoggerAppExtras, ··· 17 18 * 18 19 * @see Logger 19 20 * */ 20 - export const buildLogger = (defaultLevel: LogLevel, streams: LogLevelStreamEntry[]): Logger => { 21 + export const buildLogger = (defaultLevel: LogLevel, streams: LogLevelStreamEntry[], extras: PinoLoggerOptions = {}): Logger => { 21 22 // TODO maybe implement custom levels 22 23 //const { levels = {} } = extras; 23 24 ··· 40 41 level: defaultLevel, 41 42 customLevels: CUSTOM_LEVELS, 42 43 useOnlyCustomLevels: false, 44 + ...extras 43 45 }, pino.multistream(streams)) as Logger; 44 46 plogger.labels = []; 45 47 ··· 95 97 const { 96 98 pretty = {}, 97 99 destinations = [], 100 + pino, 98 101 } = extras || {}; 99 102 100 103 const options = parseLogOptions(config); ··· 115 118 } 116 119 } 117 120 118 - const logger = buildLogger('debug' as LogLevel, streams); 121 + const logger = buildLogger('debug' as LogLevel, streams, pino); 119 122 if (error !== undefined) { 120 123 logger.warn(error); 121 124 } ··· 130 133 const { 131 134 pretty = {}, 132 135 destinations = [], 136 + pino 133 137 } = extras || {}; 134 138 135 139 const options = parseLogOptions(config); ··· 149 153 error = e; 150 154 } 151 155 } 152 - const logger = buildLogger('debug' as LogLevel, streams); 156 + const logger = buildLogger('debug' as LogLevel, streams, pino); 153 157 if (error !== undefined) { 154 158 logger.warn(error); 155 159 }
+10 -1
src/types.ts
··· 167 167 * */ 168 168 pretty?: PrettyOptions 169 169 /** 170 - * Additional logging destinations to use alongside the built-in console/log stream. These can be any created by buildDestination* functions or other [Pino Transports](https://getpino.io/#/docs/transports?id=known-transports) 170 + * Additional logging destinations to use alongside the built-in console/log stream. These can be any created by `buildDestination*` functions or other [Pino Transports](https://getpino.io/#/docs/transports?id=known-transports) 171 171 * */ 172 172 destinations?: LogLevelStreamEntry[] 173 + /** 174 + * Additional [Pino Log options](https://getpino.io/#/docs/api?id=options) that are passed to `pino()` on logger creation 175 + * */ 176 + pino?: PinoLoggerOptions 173 177 } 174 178 175 179 /** ··· 181 185 verbose: 25, 182 186 log: 21 183 187 } 188 + 189 + /** 190 + * Additional [Pino Log options](https://getpino.io/#/docs/api?id=options) that are passed to `pino()` on logger creation 191 + * */ 192 + export type PinoLoggerOptions = Omit<LoggerOptions, 'level' | 'mixin' | 'mixinMergeStrategy' | 'customLevels' | 'useOnlyCustomLevels' | 'transport'>