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