import * as log from 'loglevel'; import * as prefix from 'loglevel-plugin-prefix'; export const ppLogLevel = [ //{ value: 'trace', label: 'Trace' }, { value: 'debug', label: 'Debug' }, { value: 'info', label: 'Info' }, { value: 'warn', label: 'Warn' }, { value: 'error', label: 'Error' }, //minimum level error //{ value: 'silent', label: 'Silent' }, ]; export function load() { prefix.reg(log); log.enableAll(); /* eslint-disable @typescript-eslint/no-unused-vars */ const ANSI_RESET = '\u001B[0m'; const ANSI_BLACK = '\u001B[30m'; const ANSI_RED = '\u001B[31m'; const ANSI_GREEN = '\u001B[32m'; const ANSI_YELLOW = '\u001B[33m'; const ANSI_BLUE = '\u001B[34m'; const ANSI_PURPLE = '\u001B[35m'; const ANSI_CYAN = '\u001B[36m'; const ANSI_WHITE = '\u001B[37m'; prefix.apply(log, { format(level: string, name: string | undefined, timestamp: Date) { let colorPrefix = ''; switch (level) { case 'TRACE': colorPrefix = ANSI_PURPLE; break; case 'DEBUG': colorPrefix = ANSI_CYAN; break; case 'INFO': colorPrefix = ANSI_BLUE; break; case 'WARN': colorPrefix = ANSI_YELLOW; break; case 'ERROR': colorPrefix = ANSI_RED; break; default: colorPrefix = ANSI_RESET; break; } return `[${timestamp}] ${colorPrefix}PPDevTool/${level}${ANSI_RESET}`; }, }); applyLogLevel(); } export function applyLogLevel() { try { const logLevel = JSON.parse(localStorage.getItem('ppLogLevel') || '"warn"'); logLevel && log.setLevel(logLevel as log.LogLevelDesc); } catch { log.error('Could not apply loglevel'); } }