kidshift-be/src/logger.ts

51 lines
1.1 KiB
TypeScript
Raw Normal View History

2024-06-15 08:12:04 +00:00
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) => {
2024-06-18 02:30:26 +00:00
console.log(chalk.blue('[INFO]') + '\t ' + this.tagString() + ':\t' + message);
2024-06-15 08:12:04 +00:00
}
warn = (message: string) => {
2024-06-18 02:30:26 +00:00
console.log(chalk.yellow('[WARN]') + '\t ' + this.tagString() + ':\t' + message);
2024-06-15 08:12:04 +00:00
}
error = (message: string) => {
2024-06-18 02:30:26 +00:00
console.log(chalk.red('[ERROR]') + '\t ' + this.tagString() + ':\t' + message);
2024-06-15 08:12:04 +00:00
}
debug = (message: string) => {
2024-06-18 02:30:26 +00:00
console.log(chalk.gray('[DEBUG]' + '\t ' + this.tagString() + ':\t' + message));
2024-06-15 08:12:04 +00:00
}
2024-06-18 02:27:08 +00:00
success = (message: string) => {
2024-06-18 02:30:26 +00:00
console.log(chalk.green('[SUCC]') + '\t ' + this.tagString() + ':\t' + message);
2024-06-18 02:27:08 +00:00
}
2024-06-15 08:12:04 +00:00
}
export default Logger;