2018-07-14 04:58:21 -07:00
|
|
|
import chalk from 'chalk';
|
|
|
|
import * as dateformat from 'dateformat';
|
2016-12-29 00:36:03 -08:00
|
|
|
|
2016-12-29 06:09:21 -08:00
|
|
|
export default class Logger {
|
2017-05-24 04:50:17 -07:00
|
|
|
private domain: string;
|
2016-12-29 06:09:21 -08:00
|
|
|
|
2017-05-24 04:50:17 -07:00
|
|
|
constructor(domain: string) {
|
|
|
|
this.domain = domain;
|
|
|
|
}
|
|
|
|
|
2018-07-14 04:58:21 -07:00
|
|
|
public static log(level: string, message: string): void {
|
|
|
|
const time = dateformat(new Date(), 'HH:MM:ss');
|
|
|
|
console.log(`[${time} ${level}] ${message}`);
|
2016-12-29 03:03:34 -08:00
|
|
|
}
|
2016-12-29 06:09:21 -08:00
|
|
|
|
2017-05-24 04:50:17 -07:00
|
|
|
public static error(message: string): void {
|
2018-07-14 04:58:21 -07:00
|
|
|
(new Logger('')).error(message);
|
2016-12-29 06:09:21 -08:00
|
|
|
}
|
|
|
|
|
2017-05-24 04:50:17 -07:00
|
|
|
public static warn(message: string): void {
|
2018-07-14 04:58:21 -07:00
|
|
|
(new Logger('')).warn(message);
|
2016-12-29 06:09:21 -08:00
|
|
|
}
|
|
|
|
|
2017-05-24 04:50:17 -07:00
|
|
|
public static info(message: string): void {
|
2018-07-14 04:58:21 -07:00
|
|
|
(new Logger('')).info(message);
|
2016-12-29 06:09:21 -08:00
|
|
|
}
|
|
|
|
|
2018-07-14 04:58:21 -07:00
|
|
|
public static succ(message: string): void {
|
|
|
|
(new Logger('')).succ(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
public log(level: string, message: string) {
|
|
|
|
const domain = this.domain.length > 0 ? `[${this.domain}] ` : '';
|
|
|
|
Logger.log(level, `${domain}${message}`);
|
2016-12-29 06:09:21 -08:00
|
|
|
}
|
|
|
|
|
2017-05-24 04:50:17 -07:00
|
|
|
public error(message: string): void {
|
2018-07-14 04:58:21 -07:00
|
|
|
this.log(chalk.red.bold('ERROR'), chalk.red.bold(message));
|
2016-12-29 06:09:21 -08:00
|
|
|
}
|
|
|
|
|
2017-05-24 04:50:17 -07:00
|
|
|
public warn(message: string): void {
|
2018-07-14 04:58:21 -07:00
|
|
|
this.log(chalk.yellow.bold('WARN'), chalk.yellow.bold(message));
|
2016-12-29 06:09:21 -08:00
|
|
|
}
|
|
|
|
|
2017-05-24 04:50:17 -07:00
|
|
|
public info(message: string): void {
|
2018-07-14 04:58:21 -07:00
|
|
|
this.log(chalk.blue.bold('INFO'), message);
|
|
|
|
}
|
|
|
|
|
|
|
|
public succ(message: string): void {
|
|
|
|
this.log(chalk.blue.bold('INFO'), chalk.green.bold(message));
|
2016-12-29 06:09:21 -08:00
|
|
|
}
|
2016-12-29 00:36:03 -08:00
|
|
|
}
|