Improve log readability

This commit is contained in:
syuilo 2019-02-03 21:42:52 +09:00
parent df54da9510
commit b4859be098
No known key found for this signature in database
GPG Key ID: BDC4C49D06AB9D69
1 changed files with 4 additions and 3 deletions

View File

@ -19,15 +19,16 @@ export default class Logger {
return logger; return logger;
} }
public log(level: string, message: string, important = false): void { public log(level: string, message: string, important = false, subDomains: string[] = []): void {
if (program.quiet) return; if (program.quiet) return;
const domain = this.color ? chalk.keyword(this.color)(this.domain) : chalk.white(this.domain); const domain = this.color ? chalk.keyword(this.color)(this.domain) : chalk.white(this.domain);
const domains = [domain].concat(subDomains);
if (this.parentLogger) { if (this.parentLogger) {
this.parentLogger.log(level, `[${domain}]\t${message}`, important); this.parentLogger.log(level, message, important, domains);
} else { } else {
const time = dateformat(new Date(), 'HH:MM:ss'); const time = dateformat(new Date(), 'HH:MM:ss');
const process = cluster.isMaster ? '*' : cluster.worker.id; const process = cluster.isMaster ? '*' : cluster.worker.id;
const log = `${chalk.gray(time)} ${level} ${process}\t[${domain}]\t${message}`; const log = `${chalk.gray(time)} ${level} ${process}\t[${domains.join(' ')}]\t${message}`;
console.log(important ? chalk.bold(log) : log); console.log(important ? chalk.bold(log) : log);
} }
} }