simple-review-server/src/utils/logger.ts

41 lines
994 B
TypeScript

import chalk from "chalk";
export class Logger {
private _wrn: string;
private _err: string;
private _main: string;
constructor(origin?: string) {
this._wrn = chalk.yellow("[WARN] ");
this._err = chalk.red("[ERROR] ");
this._main = chalk.bold.gray(`[${origin ?? "Anonymous"}] `);
}
public log(text: any, args?: any): void {
args
? console.log(this._main + text, args)
: console.log(this._main + text);
}
public warn(text: any, args?: any): void {
args
? console.warn(this._main + this._wrn + text, args)
: console.warn(this._main + this._wrn + text);
}
public error(text: any, args?: any): void {
args
? console.error(this._main + this._err + text, args)
: console.error(this._main + this._err + text);
}
}
export const emp = chalk.green;
export const wrn = chalk.yellow;
export const err = chalk.red;
export const bold = chalk.bold;
export const itl = chalk.italic;
export const udln = chalk.underline;