Add `trace` logLevel

This commit is contained in:
Sidharth Vinod 2022-08-21 08:45:17 +05:30
parent fab9688135
commit d9bace053b
No known key found for this signature in database
GPG Key ID: FB5CCD378D3907CD
1 changed files with 9 additions and 1 deletions

View File

@ -1,8 +1,9 @@
import moment from 'moment-mini';
export type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'fatal';
export type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal';
export const LEVELS: Record<LogLevel, number> = {
trace: 0,
debug: 1,
info: 2,
warn: 3,
@ -11,6 +12,7 @@ export const LEVELS: Record<LogLevel, number> = {
};
export const log: Record<keyof typeof LEVELS, typeof console.log> = {
trace: (..._args: any[]) => {},
debug: (..._args: any[]) => {},
info: (..._args: any[]) => {},
warn: (..._args: any[]) => {},
@ -31,6 +33,7 @@ export const setLogLevel = function (level: keyof typeof LEVELS | number | strin
numericLevel = LEVELS[level as keyof typeof LEVELS];
}
}
log.trace = () => {};
log.debug = () => {};
log.info = () => {};
log.warn = () => {};
@ -61,6 +64,11 @@ export const setLogLevel = function (level: keyof typeof LEVELS | number | strin
? console.debug.bind(console, format('DEBUG'), 'color: lightgreen')
: console.log.bind(console, '\x1b[32m', format('DEBUG'));
}
if (numericLevel <= LEVELS.trace) {
log.trace = console.debug
? console.debug.bind(console, format('TRACE'), 'color: lightgreen')
: console.log.bind(console, '\x1b[32m', format('TRACE'));
}
};
/**