1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-28 10:09:20 -05:00

Add colors to log module (#175)

This commit is contained in:
Dmitry Sharshakov 2019-02-11 05:28:52 +03:00 committed by Ryan Dahl
parent fda9c98d05
commit d895c60a51

View file

@ -1,7 +1,8 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import { open, File, Writer } from "deno";
import { getLevelByName } from "./levels.ts";
import { getLevelByName, LogLevel } from "./levels.ts";
import { LogRecord } from "./logger.ts";
import { red, yellow, blue, bold } from "../colors/mod.ts";
const DEFAULT_FORMATTER = "{levelName} {msg}";
type FormatterFunction = (logRecord: LogRecord) => string;
@ -52,6 +53,29 @@ export class BaseHandler {
}
export class ConsoleHandler extends BaseHandler {
format(logRecord: LogRecord): string {
let msg = super.format(logRecord);
switch (logRecord.level) {
case LogLevel.INFO:
msg = blue(msg);
break;
case LogLevel.WARNING:
msg = yellow(msg);
break;
case LogLevel.ERROR:
msg = red(msg);
break;
case LogLevel.CRITICAL:
msg = bold(red(msg));
break;
default:
break;
}
return msg;
}
log(msg: string) {
console.log(msg);
}