Update logger
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { log } from './logger';
|
||||
import Logger from './logger';
|
||||
import { exec } from 'shelljs';
|
||||
|
||||
export default function(): void {
|
||||
@@ -14,9 +14,10 @@ function checkDependency(serviceName: string, command: string, transform: (x: st
|
||||
notFound: 127
|
||||
};
|
||||
const x = exec(command, { silent: true }) as any;
|
||||
let depsLogger = new Logger('Deps');
|
||||
if (x.code === code.success) {
|
||||
log('Info', `${serviceName} ${transform(x.stdout)} found`, 'Deps');
|
||||
depsLogger.info(`${serviceName} ${transform(x.stdout)} found`);
|
||||
} else if (x.code === code.notFound) {
|
||||
log('Warn', `${serviceName} not found`, 'Deps');
|
||||
depsLogger.warn(`${serviceName} not found`);
|
||||
}
|
||||
}
|
||||
|
@@ -10,17 +10,44 @@ function toLevelColor(level: LogLevel): chalk.ChalkStyle {
|
||||
}
|
||||
}
|
||||
|
||||
export function log(message: string): void;
|
||||
export function log(level: LogLevel, message: string): void;
|
||||
export function log(level: LogLevel, message: string, domain: string): void;
|
||||
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;
|
||||
if (typeof domain == 'string') {
|
||||
log(level, `[${domain}] ${message}`);
|
||||
} else {
|
||||
export default class Logger {
|
||||
domain: string;
|
||||
|
||||
static log(level: LogLevel, message: string): void {
|
||||
let color = toLevelColor(level);
|
||||
let time = (new Date()).toLocaleTimeString('ja-JP');
|
||||
console.log(`[${time} ${color.bold(level.toUpperCase())}]: ${message}`);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user