Merge pull request #2692 from lkiesow/log-src

Fix log source in log file
This commit is contained in:
advplyr 2024-02-29 17:01:59 -06:00 committed by GitHub
commit 49af7eb7b0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -70,14 +70,15 @@ class Logger {
} }
/** /**
* *
* @param {number} level * @param {number} level
* @param {string[]} args * @param {string[]} args
* @param {string} src
*/ */
async handleLog(level, args) { async handleLog(level, args, src) {
const logObj = { const logObj = {
timestamp: this.timestamp, timestamp: this.timestamp,
source: this.source, source: src,
message: args.join(' '), message: args.join(' '),
levelName: this.getLogLevelString(level), levelName: this.getLogLevelString(level),
level level
@ -104,31 +105,31 @@ class Logger {
trace(...args) { trace(...args) {
if (this.logLevel > LogLevel.TRACE) return if (this.logLevel > LogLevel.TRACE) return
console.trace(`[${this.timestamp}] TRACE:`, ...args) console.trace(`[${this.timestamp}] TRACE:`, ...args)
this.handleLog(LogLevel.TRACE, args) this.handleLog(LogLevel.TRACE, args, this.source)
} }
debug(...args) { debug(...args) {
if (this.logLevel > LogLevel.DEBUG) return if (this.logLevel > LogLevel.DEBUG) return
console.debug(`[${this.timestamp}] DEBUG:`, ...args, `(${this.source})`) console.debug(`[${this.timestamp}] DEBUG:`, ...args, `(${this.source})`)
this.handleLog(LogLevel.DEBUG, args) this.handleLog(LogLevel.DEBUG, args, this.source)
} }
info(...args) { info(...args) {
if (this.logLevel > LogLevel.INFO) return if (this.logLevel > LogLevel.INFO) return
console.info(`[${this.timestamp}] INFO:`, ...args) console.info(`[${this.timestamp}] INFO:`, ...args)
this.handleLog(LogLevel.INFO, args) this.handleLog(LogLevel.INFO, args, this.source)
} }
warn(...args) { warn(...args) {
if (this.logLevel > LogLevel.WARN) return if (this.logLevel > LogLevel.WARN) return
console.warn(`[${this.timestamp}] WARN:`, ...args, `(${this.source})`) console.warn(`[${this.timestamp}] WARN:`, ...args, `(${this.source})`)
this.handleLog(LogLevel.WARN, args) this.handleLog(LogLevel.WARN, args, this.source)
} }
error(...args) { error(...args) {
if (this.logLevel > LogLevel.ERROR) return if (this.logLevel > LogLevel.ERROR) return
console.error(`[${this.timestamp}] ERROR:`, ...args, `(${this.source})`) console.error(`[${this.timestamp}] ERROR:`, ...args, `(${this.source})`)
this.handleLog(LogLevel.ERROR, args) this.handleLog(LogLevel.ERROR, args, this.source)
} }
/** /**
@ -139,12 +140,12 @@ class Logger {
*/ */
fatal(...args) { fatal(...args) {
console.error(`[${this.timestamp}] FATAL:`, ...args, `(${this.source})`) console.error(`[${this.timestamp}] FATAL:`, ...args, `(${this.source})`)
return this.handleLog(LogLevel.FATAL, args) return this.handleLog(LogLevel.FATAL, args, this.source)
} }
note(...args) { note(...args) {
console.log(`[${this.timestamp}] NOTE:`, ...args) console.log(`[${this.timestamp}] NOTE:`, ...args)
this.handleLog(LogLevel.NOTE, args) this.handleLog(LogLevel.NOTE, args, this.source)
} }
} }
module.exports = new Logger() module.exports = new Logger()