From d9bace053b9105bfed99b00a244d20273601927b Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Sun, 21 Aug 2022 08:45:17 +0530 Subject: [PATCH] Add `trace` logLevel --- src/logger.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/logger.ts b/src/logger.ts index a57285c7b..195cde7f3 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -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 = { + trace: 0, debug: 1, info: 2, warn: 3, @@ -11,6 +12,7 @@ export const LEVELS: Record = { }; export const log: Record = { + 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')); + } }; /**