mirror of
https://github.com/r-ca/kidshift-be.git
synced 2024-10-26 00:24:02 +00:00
logger実装
This commit is contained in:
parent
846d27f5ce
commit
eda7ba2028
46
src/logger.ts
Normal file
46
src/logger.ts
Normal file
|
@ -0,0 +1,46 @@
|
|||
import chalk from 'chalk';
|
||||
|
||||
class Logger {
|
||||
|
||||
private tags: string[] = [];
|
||||
|
||||
constructor() {
|
||||
this.tags.push('default');
|
||||
}
|
||||
|
||||
setTags(tags: string[]) {
|
||||
this.tags = tags;
|
||||
}
|
||||
|
||||
setTag(tag: string) {
|
||||
this.tags = [tag];
|
||||
}
|
||||
|
||||
getChild(tag: string) {
|
||||
const child = new Logger();
|
||||
child.setTags([...this.tags, tag]);
|
||||
return child;
|
||||
}
|
||||
|
||||
private tagString() {
|
||||
return this.tags.join('/');
|
||||
}
|
||||
|
||||
info = (message: string) => {
|
||||
console.log(chalk.blue('[INFO ]') + ' ' + this.tagString() + ':\t' + message);
|
||||
}
|
||||
|
||||
warn = (message: string) => {
|
||||
console.log(chalk.yellow('[WARN ]') + ' ' + this.tagString() + ':\t' + message);
|
||||
}
|
||||
|
||||
error = (message: string) => {
|
||||
console.log(chalk.red('[ERROR]') + ' ' + this.tagString() + ':\t' + message);
|
||||
}
|
||||
|
||||
debug = (message: string) => {
|
||||
console.log(chalk.gray('[DEBUG]' + ' ' + this.tagString() + ':\t' + message));
|
||||
}
|
||||
}
|
||||
|
||||
export default Logger;
|
Loading…
Reference in New Issue
Block a user