| 12345678910111213141516171819202122232425262728293031 |
- export type LogLevel = 'ERROR' | 'WARNING' | 'INFO' | 'DEBUG';
- export class Logger {
- public static get LOG_LEVELS(): Array<LogLevel> {
- return ['ERROR', 'WARNING', 'INFO', 'DEBUG'];
- }
- private static levels: Array<LogLevel> = this.LOG_LEVELS.slice(0, 3);
- public static set logLevel(logLevel: LogLevel) {
- Logger.levels = Logger.LOG_LEVELS.slice(0, Logger.LOG_LEVELS.indexOf(logLevel) + 1);
- }
- public static get logLevel(): LogLevel {
- return Logger.levels[Logger.levels.length - 1];
- }
- public static debug(...data: any[]) {
- if (Logger.levels.includes('DEBUG')) console.log(...data);
- }
- public static info(...data: any[]) {
- if (Logger.levels.includes('INFO')) console.log(...data);
- }
- public static warn(...data: any[]) {
- if (Logger.levels.includes('WARNING')) console.warn(...data);
- }
- public static error(...data: any[]) {
- if (Logger.levels.includes('ERROR')) console.error(...data);
- }
- }
|