2016-12-29 08:36:03 +00: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 12:14:47 +00:00
|
|
|
export function log(message: string): void;
|
2016-12-29 11:03:34 +00:00
|
|
|
export function log(level: LogLevel, message: string): void;
|
|
|
|
export function log(level: LogLevel, message: string, domain: string): void;
|
2016-12-29 12:14:47 +00:00
|
|
|
export function log(x: string | LogLevel, message?: string, domain?: string): void {
|
|
|
|
const level = typeof message == 'undefined' ? 'Info' : x as LogLevel;
|
|
|
|
message = typeof message == 'undefined' ? x : message;
|
2016-12-29 11:03:34 +00:00
|
|
|
if (typeof domain == 'string') {
|
|
|
|
log(level, `[${domain}] ${message}`);
|
|
|
|
} else {
|
|
|
|
let color = toLevelColor(level);
|
|
|
|
let time = (new Date()).toLocaleTimeString('ja-JP');
|
|
|
|
console.log(`[${time} ${color.bold(level.toUpperCase())}]: ${message}`);
|
|
|
|
}
|
2016-12-29 08:36:03 +00:00
|
|
|
}
|