2016-12-29 02:36:03 -06:00
|
|
|
import * as chalk from 'chalk';
|
|
|
|
|
|
|
|
export type LogLevel = 'Error' | 'Warn' | 'Info';
|
|
|
|
|
|
|
|
function toLevelColor(level: LogLevel): chalk.ChalkStyle {
|
|
|
|
switch (level) {
|
|
|
|
case 'Error': return chalk.red;
|
|
|
|
case 'Warn': return chalk.yellow;
|
|
|
|
case 'Info': return chalk.blue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function log(level: LogLevel, message: string): void {
|
|
|
|
let color = toLevelColor(level);
|
2016-12-29 03:07:37 -06:00
|
|
|
let time = (new Date()).toLocaleTimeString([], { hour12: false });
|
|
|
|
console.log(`[${time} ${color.bold(level.toUpperCase())}]: ${message}`);
|
2016-12-29 02:36:03 -06:00
|
|
|
}
|