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,29 +9,7 @@ export interface ConsoleHandlerOptions extends BaseHandlerOptions {
useColors?: boolean;
}
/**
* This is the default logger. It will output color coded log messages to the
* console via `console.log()`.
*/
export class ConsoleHandler extends BaseHandler {
#useColors?: boolean;
constructor(levelName: LevelName, options: ConsoleHandlerOptions = {}) {
super(levelName, options);
this.#useColors = options.useColors ?? true;
}
override format(logRecord: LogRecord): string {
let msg = super.format(logRecord);
if (this.#useColors) {
msg = this.applyColors(msg, logRecord.level);
}
return msg;
}
applyColors(msg: string, level: number): string {
function applyColors(msg: string, level: number): string {
switch (level) {
case LogLevels.INFO:
msg = blue(msg);
@ -49,6 +27,28 @@ export class ConsoleHandler extends BaseHandler {
break;
}
return msg;
}
/**
* This is the default logger. It will output color coded log messages to the
* console via `console.log()`.
*/
export class ConsoleHandler extends BaseHandler {
#useColors?: boolean;
constructor(levelName: LevelName, options: ConsoleHandlerOptions = {}) {
super(levelName, options);
this.#useColors = options.useColors ?? true;
}
override format(logRecord: LogRecord): string {
let msg = super.format(logRecord);
if (this.#useColors) {
msg = applyColors(msg, logRecord.level);
}
return msg;
}