diff --git a/server/Logger.js b/server/Logger.js index 2bdce9ac..1cf53074 100644 --- a/server/Logger.js +++ b/server/Logger.js @@ -22,6 +22,14 @@ class Logger { return 'UNKNOWN' } + get source() { + try { + throw new Error(); + } catch (error) { + return error.stack.split('\n')[3].replace(/^.*\/([^/]*:[0-9]*:[[0-9]*)\)*/, '$1') + } + } + getLogLevelString(level) { for (const key in LogLevel) { if (LogLevel[key] === level) { @@ -55,6 +63,7 @@ class Logger { handleLog(level, args) { const logObj = { timestamp: this.timestamp, + source: this.source, message: args.join(' '), levelName: this.getLogLevelString(level), level @@ -78,41 +87,41 @@ class Logger { trace(...args) { if (this.logLevel > LogLevel.TRACE) return - console.trace(`[${this.timestamp}] TRACE:`, ...args) + console.trace(`[${this.timestamp}[ (${this.source}) TRACE:`, ...args) this.handleLog(LogLevel.TRACE, args) } debug(...args) { if (this.logLevel > LogLevel.DEBUG) return - console.debug(`[${this.timestamp}] DEBUG:`, ...args) + console.debug(`[${this.timestamp}[ (${this.source}) DEBUG:`, ...args) this.handleLog(LogLevel.DEBUG, args) } info(...args) { if (this.logLevel > LogLevel.INFO) return - console.info(`[${this.timestamp}] INFO:`, ...args) + console.info(`[${this.timestamp}] (${this.source}) INFO:`, ...args) this.handleLog(LogLevel.INFO, args) } warn(...args) { if (this.logLevel > LogLevel.WARN) return - console.warn(`[${this.timestamp}] WARN:`, ...args) + console.warn(`[${this.timestamp}] (${this.source}) WARN:`, ...args) this.handleLog(LogLevel.WARN, args) } error(...args) { if (this.logLevel > LogLevel.ERROR) return - console.error(`[${this.timestamp}] ERROR:`, ...args) + console.error(`[${this.timestamp}] (${this.source}) ERROR:`, ...args) this.handleLog(LogLevel.ERROR, args) } fatal(...args) { - console.error(`[${this.timestamp}] FATAL:`, ...args) + console.error(`[${this.timestamp}] (${this.source}) FATAL:`, ...args) this.handleLog(LogLevel.FATAL, args) } note(...args) { - console.log(`[${this.timestamp}] NOTE:`, ...args) + console.log(`[${this.timestamp}] (${this.source}) NOTE:`, ...args) this.handleLog(LogLevel.NOTE, args) } }