From 364a6dd2aa9316f3f46ce0894a49ae17444d8af4 Mon Sep 17 00:00:00 2001 From: Andrew Berry Date: Wed, 2 Mar 2022 14:07:22 -0500 Subject: [PATCH] Only colorize output if logging to a tty (#11645) --- lib/util/logger.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/util/logger.ts b/lib/util/logger.ts index 7d3ae49e8..7723d24f6 100644 --- a/lib/util/logger.ts +++ b/lib/util/logger.ts @@ -62,7 +62,12 @@ const transportsToUse: winston.transport[] = [ winston.format.printf(/* istanbul ignore next */(info) => { const {timestamp, level, message} = info; const l = winstonToZ2mLevel(level as WinstonLogLevel); - const prefix = colorizer.colorize(l, `Zigbee2MQTT:${levelWithCompensatedLength[l]}`); + + const plainPrefix = `Zigbee2MQTT:${levelWithCompensatedLength[l]}`; + let prefix = plainPrefix; + if (process.stdout.isTTY) { + prefix = colorizer.colorize(l, plainPrefix); + } return `${prefix} ${timestamp.split('.')[0]}: ${message}`; }), ),