-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.ts
More file actions
37 lines (31 loc) · 1.1 KB
/
logger.ts
File metadata and controls
37 lines (31 loc) · 1.1 KB
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
import { CONFIG, type LogLevel } from './config'
/**
* Simple logging utilities for the extension
*/
const prefix = `[${CONFIG.EXTENSION_NAME}]`
// No-op function for disabled logging
const noop = () => {}
// Log level hierarchy - index represents priority
const LOG_LEVEL_PRIORITY: Record<LogLevel, number> = {
DEBUG: 0,
ERROR: 3,
INFO: 1,
WARN: 2,
}
// Helper function to check if a log level is enabled
const shouldLog = (level: LogLevel): boolean => {
// Don't log anything in production mode
if (CONFIG.MODE === 'PROD') {
return false
}
return LOG_LEVEL_PRIORITY[level] >= LOG_LEVEL_PRIORITY[CONFIG.LOG_LEVEL]
}
// Export simple logging functions
export const logger = {
debug: shouldLog('DEBUG') ? console.log.bind(console, prefix) : noop,
error: shouldLog('ERROR') ? console.error.bind(console, prefix) : noop,
info: shouldLog('INFO') ? console.log.bind(console, prefix) : noop,
time: shouldLog('INFO') ? console.time.bind(console) : noop,
timeEnd: shouldLog('INFO') ? console.timeEnd.bind(console) : noop,
warn: shouldLog('WARN') ? console.warn.bind(console, prefix) : noop,
}