Skip to content

Commit 5f25b9c

Browse files
Merge pull request #15577 from kerryChen95/master
Add color allowance check to console logger options
2 parents 6634a2d + e3e744b commit 5f25b9c

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

packages/common/services/console-logger.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { inspect, InspectOptions } from 'util';
22
import { Injectable, Optional } from '../decorators/core';
3-
import { clc, yellow } from '../utils/cli-colors.util';
3+
import { clc, yellow, isColorAllowed } from '../utils/cli-colors.util';
44
import {
55
isFunction,
66
isPlainObject,
@@ -154,7 +154,7 @@ export class ConsoleLogger implements LoggerService {
154154

155155
opts = opts ?? {};
156156
opts.logLevels ??= DEFAULT_LOG_LEVELS;
157-
opts.colors ??= opts.colors ?? (opts.json ? false : true);
157+
opts.colors ??= opts.colors ?? (opts.json ? false : isColorAllowed());
158158
opts.prefix ??= 'Nest';
159159

160160
this.options = opts;

packages/common/utils/cli-colors.util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
type ColorTextFn = (text: string) => string;
22

3-
const isColorAllowed = () => !process.env.NO_COLOR;
3+
export const isColorAllowed = () => !process.env.NO_COLOR;
44
const colorIfAllowed = (colorFn: ColorTextFn) => (text: string) =>
55
isColorAllowed() ? colorFn(text) : text;
66

0 commit comments

Comments
 (0)