summaryrefslogtreecommitdiff
path: root/src/misc
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2019-02-03 01:39:42 +0900
committersyuilo <syuilotan@yahoo.co.jp>2019-02-03 01:39:42 +0900
commitf53a93ea137b3a184f91f9a0e72a8c5eb1e790fc (patch)
tree87ff012c668bef036956cdfb605f028eb072c1b6 /src/misc
parentBetter logs (diff)
downloadmisskey-f53a93ea137b3a184f91f9a0e72a8c5eb1e790fc.tar.gz
misskey-f53a93ea137b3a184f91f9a0e72a8c5eb1e790fc.tar.bz2
misskey-f53a93ea137b3a184f91f9a0e72a8c5eb1e790fc.zip
Better logger
Diffstat (limited to 'src/misc')
-rw-r--r--src/misc/logger.ts13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/misc/logger.ts b/src/misc/logger.ts
index 2ca79dd4b6..bfdb48c646 100644
--- a/src/misc/logger.ts
+++ b/src/misc/logger.ts
@@ -3,24 +3,27 @@ import * as dateformat from 'dateformat';
export default class Logger {
private domain: string;
+ private color?: string;
private parentLogger: Logger;
- constructor(domain: string) {
+ constructor(domain: string, color?: string) {
this.domain = domain;
+ this.color = color;
}
- public createSubLogger(domain: string): Logger {
- const logger = new Logger(domain);
+ public createSubLogger(domain: string, color?: string): Logger {
+ const logger = new Logger(domain, color);
logger.parentLogger = this;
return logger;
}
public log(level: string, message: string, important = false): void {
+ const domain = this.color ? chalk.keyword(this.color)(this.domain) : chalk.white(this.domain);
if (this.parentLogger) {
- this.parentLogger.log(level, `[${this.domain}]\t${message}`, important);
+ this.parentLogger.log(level, `[${domain}]\t${message}`, important);
} else {
const time = dateformat(new Date(), 'HH:MM:ss');
- const log = `${chalk.gray(time)} ${level} [${this.domain}]\t${message}`;
+ const log = `${chalk.gray(time)} ${level} [${domain}]\t${message}`;
console.log(important ? chalk.bold(log) : log);
}
}