mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
feat(core): Comply with NO_COLOR
in logs (#12347)
This commit is contained in:
parent
78ef2ce7f0
commit
1e60bbcf16
|
@ -32,6 +32,9 @@ export class Logger implements LoggerType {
|
||||||
return this.scopes.size > 0;
|
return this.scopes.size > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** https://no-color.org/ */
|
||||||
|
private readonly noColor = process.env.NO_COLOR !== undefined && process.env.NO_COLOR !== '';
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly globalConfig: GlobalConfig,
|
private readonly globalConfig: GlobalConfig,
|
||||||
private readonly instanceSettingsConfig: InstanceSettingsConfig,
|
private readonly instanceSettingsConfig: InstanceSettingsConfig,
|
||||||
|
@ -129,18 +132,22 @@ export class Logger implements LoggerType {
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private color() {
|
||||||
|
return this.noColor ? winston.format.uncolorize() : winston.format.colorize({ all: true });
|
||||||
|
}
|
||||||
|
|
||||||
private debugDevConsoleFormat() {
|
private debugDevConsoleFormat() {
|
||||||
return winston.format.combine(
|
return winston.format.combine(
|
||||||
winston.format.metadata(),
|
winston.format.metadata(),
|
||||||
winston.format.timestamp({ format: () => this.devTsFormat() }),
|
winston.format.timestamp({ format: () => this.devTsFormat() }),
|
||||||
winston.format.colorize({ all: true }),
|
this.color(),
|
||||||
this.scopeFilter(),
|
this.scopeFilter(),
|
||||||
winston.format.printf(({ level: _level, message, timestamp, metadata: _metadata }) => {
|
winston.format.printf(({ level: rawLevel, message, timestamp, metadata: rawMetadata }) => {
|
||||||
const SEPARATOR = ' '.repeat(3);
|
const separator = ' '.repeat(3);
|
||||||
const LOG_LEVEL_COLUMN_WIDTH = 15; // 5 columns + ANSI color codes
|
const logLevelColumnWidth = this.noColor ? 5 : 15; // when colorizing, account for ANSI color codes
|
||||||
const level = _level.toLowerCase().padEnd(LOG_LEVEL_COLUMN_WIDTH, ' ');
|
const level = rawLevel.toLowerCase().padEnd(logLevelColumnWidth, ' ');
|
||||||
const metadata = this.toPrintable(_metadata);
|
const metadata = this.toPrintable(rawMetadata);
|
||||||
return [timestamp, level, message + ' ' + pc.dim(metadata)].join(SEPARATOR);
|
return [timestamp, level, message + ' ' + pc.dim(metadata)].join(separator);
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -149,10 +156,11 @@ export class Logger implements LoggerType {
|
||||||
return winston.format.combine(
|
return winston.format.combine(
|
||||||
winston.format.metadata(),
|
winston.format.metadata(),
|
||||||
winston.format.timestamp(),
|
winston.format.timestamp(),
|
||||||
|
this.color(),
|
||||||
this.scopeFilter(),
|
this.scopeFilter(),
|
||||||
winston.format.printf(({ level, message, timestamp, metadata }) => {
|
winston.format.printf(({ level, message, timestamp, metadata: rawMetadata }) => {
|
||||||
const _metadata = this.toPrintable(metadata);
|
const metadata = this.toPrintable(rawMetadata);
|
||||||
return `${timestamp} | ${level.padEnd(5)} | ${message}${_metadata ? ' ' + _metadata : ''}`;
|
return `${timestamp} | ${level.padEnd(5)} | ${message}${metadata ? ' ' + metadata : ''}`;
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue