# All files / utils logger.ts

82.05% Statements 32/39
50% Branches 7/14
90% Functions 9/10
85.29% Lines 29/34

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    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
    538x
    8x

    8x
    8x
    8x
    8x
    8x
    8x
    8x
    48x
    48x

    8x
    1x

    8x
    1x

    8x
    1x

    8x
    3x

    63x
    21x
    21x

    8x

    8x
    2x
    2x

    8x
    8x
    8x
     import { _global, _support } from './global'
    const PREFIX = 'MITO Logger'

    export class Logger {
      private enabled = false
      private _console: Console = {} as Console
      constructor() {
        Eif (_global.console) {
          const logType = ['log', 'debug', 'info', 'warn', 'error', 'assert']
          logType.forEach((level) => {
            Iif (!(level in _global.console)) return
            this._console[level] = _global.console[level]
          })
        }
      }
      disable(): void {
        this.enabled = false
      }

      bindOptions(debug: boolean): void {
        this.enabled = debug ? true : false
      }

      enable(): void {
        this.enabled = true
      }

      getEnableStatus() {
        return this.enabled
      }

      log(...args: any[]): void {
        Eif (!this.enabled) {
          return
        }
        this._console.log(`${PREFIX}[Log]:`, ...args)
      }
      warn(...args: any[]): void {
        if (!this.enabled) {
          return
        }
        this._console.warn(`${PREFIX}[Warn]:`, ...args)
      }
      error(...args: any[]): void {
        Eif (!this.enabled) {
          return
        }
        this._console.error(`${PREFIX}[Error]:`, ...args)
      }
    }
    const logger = _support.logger || (_support.logger = new Logger())
    export { logger }