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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-29 08:09:21 -06:00
|
|
|
export default class Logger {
|
|
|
|
domain: string;
|
|
|
|
|
|
|
|
static log(level: LogLevel, message: string): void {
|
2016-12-29 05:03:34 -06:00
|
|
|
let color = toLevelColor(level);
|
|
|
|
let time = (new Date()).toLocaleTimeString('ja-JP');
|
|
|
|
console.log(`[${time} ${color.bold(level.toUpperCase())}]: ${message}`);
|
|
|
|
}
|
2016-12-29 08:09:21 -06:00
|
|
|
|
|
|
|
static error(message: string): void {
|
|
|
|
Logger.log('Error', message);
|
|
|
|
}
|
|
|
|
|
|
|
|
static warn(message: string): void {
|
|
|
|
Logger.log('Warn', message);
|
|
|
|
}
|
|
|
|
|
|
|
|
static info(message: string): void {
|
|
|
|
Logger.log('Info', message);
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor(domain: string) {
|
|
|
|
this.domain = domain;
|
|
|
|
}
|
|
|
|
|
|
|
|
log(level: LogLevel, message: string): void {
|
|
|
|
Logger.log(level, `[${this.domain}] ${message}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
error(message: string): void {
|
|
|
|
this.log('Error', message);
|
|
|
|
}
|
|
|
|
|
|
|
|
warn(message: string): void {
|
|
|
|
this.log('Warn', message);
|
|
|
|
}
|
|
|
|
|
|
|
|
info(message: string): void {
|
|
|
|
this.log('Info', message);
|
|
|
|
}
|
2016-12-29 02:36:03 -06:00
|
|
|
}
|