fix(log): remove leaky ConsoleHandler.prototype.applyColors() (#6072)

fix(log): remove leaky `applyColors` method
This commit is contained in:
Asher Gomez 2024-09-29 16:37:19 +10:00 committed by GitHub
parent 2916cb8977
commit 106b7077d8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -9,6 +9,27 @@ export interface ConsoleHandlerOptions extends BaseHandlerOptions {
useColors?: boolean;
}
function applyColors(msg: string, level: number): string {
switch (level) {
case LogLevels.INFO:
msg = blue(msg);
break;
case LogLevels.WARN:
msg = yellow(msg);
break;
case LogLevels.ERROR:
msg = red(msg);
break;
case LogLevels.CRITICAL:
msg = bold(red(msg));
break;
default:
break;
}
return msg;
}
/**
* This is the default logger. It will output color coded log messages to the
* console via `console.log()`.
@ -25,28 +46,7 @@ export class ConsoleHandler extends BaseHandler {
let msg = super.format(logRecord);
if (this.#useColors) {
msg = this.applyColors(msg, logRecord.level);
}
return msg;
}
applyColors(msg: string, level: number): string {
switch (level) {
case LogLevels.INFO:
msg = blue(msg);
break;
case LogLevels.WARN:
msg = yellow(msg);
break;
case LogLevels.ERROR:
msg = red(msg);
break;
case LogLevels.CRITICAL:
msg = bold(red(msg));
break;
default:
break;
msg = applyColors(msg, logRecord.level);
}
return msg;