nitro-renderer/src/core/common/NitroLogger.ts

87 lines
1.9 KiB
TypeScript
Raw Normal View History

2022-10-29 22:59:33 -04:00
import { INitroLogger } from '../../api';
2021-03-16 22:02:09 -04:00
export class NitroLogger implements INitroLogger
{
private _name: string;
private _description: string | number;
private _print: boolean;
constructor(name: string, description: string | number = null)
{
2022-03-02 19:21:30 -05:00
this._name = name;
this._description = description;
this._print = true;
2021-03-16 22:02:09 -04:00
}
2022-07-18 21:51:53 -04:00
public log(...message: any[]): void
2021-03-16 22:02:09 -04:00
{
2022-07-18 21:51:53 -04:00
this.printMessage('log', ...message);
2021-03-16 22:02:09 -04:00
}
2022-07-18 21:51:53 -04:00
public error(...message: any[]): void
2021-03-16 22:02:09 -04:00
{
2022-07-18 21:51:53 -04:00
this.printMessage('error', ...message);
2021-03-16 22:02:09 -04:00
}
2022-07-18 21:51:53 -04:00
public warn(...message: any[]): void
2021-03-16 22:02:09 -04:00
{
2022-07-18 21:51:53 -04:00
this.printMessage('warn', ...message);
2021-03-16 22:02:09 -04:00
}
2022-07-18 21:51:53 -04:00
public printMessage(modus: string, ...message: any[]): void
2021-03-16 22:02:09 -04:00
{
2022-10-29 22:59:33 -04:00
if (!this._print) return;
2021-03-16 22:02:09 -04:00
2022-07-18 21:51:53 -04:00
NitroLogger.log(this._name, modus, ...message);
2021-03-16 22:02:09 -04:00
}
2022-07-18 21:51:53 -04:00
public static log(name: string = 'Nitro', modus: string = null, ...message: any[]): void
2021-03-16 22:02:09 -04:00
{
2022-07-18 21:51:53 -04:00
const logPrefix = `[Nitro] [${name}]`;
2021-03-16 22:02:09 -04:00
2022-10-29 22:59:33 -04:00
switch (modus)
2021-03-16 22:02:09 -04:00
{
case 'error':
2022-07-18 21:51:53 -04:00
console.error(logPrefix, ...message);
2021-03-16 22:02:09 -04:00
break;
case 'warn':
2022-07-18 21:51:53 -04:00
console.warn(logPrefix, ...message);
2021-03-16 22:02:09 -04:00
break;
case 'log':
default:
2022-07-18 21:51:53 -04:00
console.log(logPrefix, ...message);
2021-03-16 22:02:09 -04:00
break;
}
}
2022-07-18 21:51:53 -04:00
public static error(name: string = 'Nitro', ...message: any[]): void
2022-03-21 01:53:14 -04:00
{
2022-07-18 21:51:53 -04:00
return this.log(name, 'error', ...message);
2022-03-21 01:53:14 -04:00
}
2022-07-18 21:51:53 -04:00
public static warn(name: string = 'Nitro', ...message: any[]): void
2021-03-16 22:02:09 -04:00
{
2022-07-18 21:51:53 -04:00
return this.log(name, 'warn', ...message);
2021-03-16 22:02:09 -04:00
}
public get description(): string | number
{
return this._description;
}
public set description(description: string | number)
{
this._description = description;
}
public get print(): boolean
{
return this._print;
}
public set print(flag: boolean)
{
this._print = flag;
}
}