1- import { CONFIG } from './config'
1+ import { CONFIG , type LogLevel } from './config'
22
33/**
44 * Simple logging utilities for the extension
@@ -9,12 +9,25 @@ const prefix = `[${CONFIG.EXTENSION_NAME}]`
99// No-op function for disabled logging
1010const noop = ( ) => { }
1111
12+ // Log level hierarchy - index represents priority
13+ const LOG_LEVEL_PRIORITY : Record < LogLevel , number > = {
14+ DEBUG : 0 ,
15+ ERROR : 3 ,
16+ INFO : 1 ,
17+ WARN : 2 ,
18+ }
19+
20+ // Helper function to check if a log level is enabled
21+ const shouldLog = ( level : LogLevel ) : boolean => {
22+ return LOG_LEVEL_PRIORITY [ level ] >= LOG_LEVEL_PRIORITY [ CONFIG . LOG_LEVEL ]
23+ }
24+
1225// Export simple logging functions
1326export const logger = {
14- debug : CONFIG . DEBUG ? console . log . bind ( console , prefix ) : noop ,
15- error : console . error . bind ( console , prefix ) ,
16- info : CONFIG . DEBUG ? console . log . bind ( console , prefix ) : noop ,
17- time : CONFIG . DEBUG ? console . time . bind ( console ) : noop ,
18- timeEnd : CONFIG . DEBUG ? console . timeEnd . bind ( console ) : noop ,
19- warn : console . warn . bind ( console , prefix ) ,
27+ debug : shouldLog ( ' DEBUG' ) ? console . log . bind ( console , prefix ) : noop ,
28+ error : shouldLog ( 'ERROR' ) ? console . error . bind ( console , prefix ) : noop ,
29+ info : shouldLog ( 'INFO' ) ? console . log . bind ( console , prefix ) : noop ,
30+ time : shouldLog ( 'INFO' ) ? console . time . bind ( console ) : noop ,
31+ timeEnd : shouldLog ( 'INFO' ) ? console . timeEnd . bind ( console ) : noop ,
32+ warn : shouldLog ( 'WARN' ) ? console . warn . bind ( console , prefix ) : noop ,
2033}
0 commit comments