All files / src/scripts/shared logger.ts

62.5% Statements 10/16
20% Branches 1/5
50% Functions 3/6
62.5% Lines 10/16

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 53 54 55 56        5x   5x         3x       5x             5x             5x                 5x     5x                 5x       5x  
// This is the only file that can call the console
/* eslint-disable no-console */
import type { Logger, LogLevel } from '../../shared/types'
 
const noop = () => {}
 
const ERROR_LOGGER: Logger = {
  debug: noop,
  info: noop,
  warn: noop,
  error(...data) {
    console.error(...data)
  },
}
 
const WARN_LOGGER: Logger = {
  ...ERROR_LOGGER,
  warn(...data) {
    console.warn(...data)
  },
}
 
const INFO_LOGGER: Logger = {
  ...WARN_LOGGER,
  info(...data) {
    console.info(...data)
  },
}
 
const DEBUG_LOGGER: Logger = {
  ...INFO_LOGGER,
  debug(...data) {
    console.debug(...data)
  },
}
 
// This template will be replaced during injection by the worker.
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
const LOG_LEVEL: LogLevel = '<LOG_LEVEL>' as unknown as LogLevel
 
function initLogger(): Logger {
  switch (LOG_LEVEL) {
    case 'info':
      return INFO_LOGGER
    case 'warn':
      return WARN_LOGGER
    case 'debug':
      return DEBUG_LOGGER
    case 'error':
    default:
      return ERROR_LOGGER
  }
}
 
export const logger: Logger = initLogger()