Skip to content

Commit e253ec9

Browse files
committed
feat(logger): add colorize option to logger configuration
1 parent 9703985 commit e253ec9

3 files changed

Lines changed: 22 additions & 17 deletions

File tree

src/config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ export let config = {
6565
* Has no effect in production.
6666
*/
6767
pretty: Env.getBoolean('LOGGER_PRETTY', true),
68+
69+
/**
70+
* Enables colorized output for pretty-print (default: true)
71+
*/
72+
colorize: Env.getBoolean('LOGGER_PRETTY_COLORIZE', true),
73+
6874
/**
6975
* Single line output for pretty-print (default: false)
7076
*/

src/utils/logger.utils.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import pino, { LoggerOptions, stdTimeFunctions } from 'pino';
2626
import type { Logger as PinoLogger } from 'pino'; // Type-only import
2727
import { config } from '../config';
2828
import { ContextStore, StoreKeys } from './context-store.utils';
29-
import { Env } from './env.utils';
3029

3130
/**
3231
* Symbol used to store the root logger in the Node.js global object.
@@ -251,22 +250,21 @@ function setupLogger(isGlobal: boolean = true): PinoLogger {
251250
timestamp: stdTimeFunctions.isoTime
252251
};
253252

254-
const logger =
255-
config.logger.pretty && Env.isDev()
256-
? pino(
257-
logParams,
258-
pino.transport({
259-
target: 'pino-pretty',
260-
options: {
261-
colorize: true,
262-
translateTime: 'SYS:standard',
263-
ignore: 'pid,hostname',
264-
singleLine: config.logger.singleLine,
265-
levelFirst: true
266-
}
267-
})
268-
)
269-
: pino(logParams);
253+
const logger = config.logger.pretty
254+
? pino(
255+
logParams,
256+
pino.transport({
257+
target: 'pino-pretty',
258+
options: {
259+
colorize: config.logger.colorize,
260+
translateTime: 'SYS:standard',
261+
ignore: 'pid,hostname',
262+
singleLine: config.logger.singleLine,
263+
levelFirst: true
264+
}
265+
})
266+
)
267+
: pino(logParams);
270268

271269
if (isGlobal) {
272270
_global[GLOBAL_LOGGER_KEY] = logger;

tests/config.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ describe('config', () => {
101101
level: 'debug',
102102
name: 'debug',
103103
pretty: false,
104+
colorize: false,
104105
singleLine: false
105106
},
106107
cache: {

0 commit comments

Comments
 (0)