mirror of
https://github.com/denoland/std.git
synced 2024-11-21 20:50:22 +00:00
fix(log): remove leaky ConsoleHandler.prototype.applyColors()
(#6072)
fix(log): remove leaky `applyColors` method
This commit is contained in:
parent
2916cb8977
commit
106b7077d8
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user