mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-08-14 01:08:22 +02:00
Init
This commit is contained in:
50
server/Logger.js
Normal file
50
server/Logger.js
Normal file
@ -0,0 +1,50 @@
|
||||
const LOG_LEVEL = {
|
||||
TRACE: 0,
|
||||
DEBUG: 1,
|
||||
INFO: 2,
|
||||
WARN: 3,
|
||||
ERROR: 4,
|
||||
FATAL: 5
|
||||
}
|
||||
|
||||
class Logger {
|
||||
constructor() {
|
||||
let env_log_level = process.env.LOG_LEVEL || 'TRACE'
|
||||
this.LogLevel = LOG_LEVEL[env_log_level] || LOG_LEVEL.TRACE
|
||||
this.info(`Log Level: ${this.LogLevel}`)
|
||||
}
|
||||
|
||||
get timestamp() {
|
||||
return (new Date()).toISOString()
|
||||
}
|
||||
|
||||
trace(...args) {
|
||||
if (this.LogLevel > LOG_LEVEL.TRACE) return
|
||||
console.trace(`[${this.timestamp}] TRACE:`, ...args)
|
||||
}
|
||||
|
||||
debug(...args) {
|
||||
if (this.LogLevel > LOG_LEVEL.DEBUG) return
|
||||
console.debug(`[${this.timestamp}] DEBUG:`, ...args)
|
||||
}
|
||||
|
||||
info(...args) {
|
||||
if (this.LogLevel > LOG_LEVEL.INFO) return
|
||||
console.info(`[${this.timestamp}] INFO:`, ...args)
|
||||
}
|
||||
|
||||
warn(...args) {
|
||||
if (this.LogLevel > LOG_LEVEL.WARN) return
|
||||
console.warn(`[${this.timestamp}] WARN:`, ...args)
|
||||
}
|
||||
|
||||
error(...args) {
|
||||
if (this.LogLevel > LOG_LEVEL.ERROR) return
|
||||
console.error(`[${this.timestamp}] ERROR:`, ...args)
|
||||
}
|
||||
|
||||
fatal(...args) {
|
||||
console.error(`[${this.timestamp}] FATAL:`, ...args)
|
||||
}
|
||||
}
|
||||
module.exports = new Logger()
|
Reference in New Issue
Block a user