File size: 1,258 Bytes
dca8ede
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
 * Simple logger utility for the application
 */
export class Logger {
  private static readonly LOG_LEVELS = {
    DEBUG: 0,
    INFO: 1,
    WARN: 2,
    ERROR: 3,
  };

  private static LOG_LEVEL = Logger.LOG_LEVELS.INFO;

  /**
   * Set the current log level
   */
  static setLogLevel(level: 'DEBUG' | 'INFO' | 'WARN' | 'ERROR'): void {
    Logger.LOG_LEVEL = Logger.LOG_LEVELS[level];
  }

  /**
   * Log debug message
   */
  static debug(message: string, ...args: any[]): void {
    if (Logger.LOG_LEVEL <= Logger.LOG_LEVELS.DEBUG) {
      console.log(`[DEBUG] ${message}`, ...args);
    }
  }

  /**
   * Log info message
   */
  static info(message: string, ...args: any[]): void {
    if (Logger.LOG_LEVEL <= Logger.LOG_LEVELS.INFO) {
      console.log(`[INFO] ${message}`, ...args);
    }
  }

  /**
   * Log warning message
   */
  static warn(message: string, ...args: any[]): void {
    if (Logger.LOG_LEVEL <= Logger.LOG_LEVELS.WARN) {
      console.warn(`[WARN] ${message}`, ...args);
    }
  }

  /**
   * Log error message
   */
  static error(message: string, ...args: any[]): void {
    if (Logger.LOG_LEVEL <= Logger.LOG_LEVELS.ERROR) {
      console.error(`[ERROR] ${message}`, ...args);
    }
  }
}

export const logger = Logger;