mirror of
				https://github.com/advplyr/audiobookshelf.git
				synced 2025-10-31 10:27:01 -04:00 
			
		
		
		
	
						commit
						f76f9c7f84
					
				| @ -22,6 +22,15 @@ class Logger { | |||||||
|     return 'UNKNOWN' |     return 'UNKNOWN' | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |   get source() { | ||||||
|  |     try { | ||||||
|  |       throw new Error() | ||||||
|  |     } catch (error) { | ||||||
|  |       const regex = global.isWin ? /^.*\\([^\\:]*:[0-9]*):[0-9]*\)*/ : /^.*\/([^/:]*:[0-9]*):[0-9]*\)*/ | ||||||
|  |       return error.stack.split('\n')[3].replace(regex, '$1') | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|   getLogLevelString(level) { |   getLogLevelString(level) { | ||||||
|     for (const key in LogLevel) { |     for (const key in LogLevel) { | ||||||
|       if (LogLevel[key] === level) { |       if (LogLevel[key] === level) { | ||||||
| @ -55,6 +64,7 @@ class Logger { | |||||||
|   handleLog(level, args) { |   handleLog(level, args) { | ||||||
|     const logObj = { |     const logObj = { | ||||||
|       timestamp: this.timestamp, |       timestamp: this.timestamp, | ||||||
|  |       source: this.source, | ||||||
|       message: args.join(' '), |       message: args.join(' '), | ||||||
|       levelName: this.getLogLevelString(level), |       levelName: this.getLogLevelString(level), | ||||||
|       level |       level | ||||||
| @ -78,13 +88,13 @@ 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) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   debug(...args) { |   debug(...args) { | ||||||
|     if (this.logLevel > LogLevel.DEBUG) return |     if (this.logLevel > LogLevel.DEBUG) return | ||||||
|     console.debug(`[${this.timestamp}] DEBUG:`, ...args) |     console.debug(`[${this.timestamp}] DEBUG:`, ...args, `(${this.source})`) | ||||||
|     this.handleLog(LogLevel.DEBUG, args) |     this.handleLog(LogLevel.DEBUG, args) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
| @ -96,18 +106,18 @@ class Logger { | |||||||
| 
 | 
 | ||||||
|   warn(...args) { |   warn(...args) { | ||||||
|     if (this.logLevel > LogLevel.WARN) return |     if (this.logLevel > LogLevel.WARN) return | ||||||
|     console.warn(`[${this.timestamp}]  WARN:`, ...args) |     console.warn(`[${this.timestamp}] WARN:`, ...args, `(${this.source})`) | ||||||
|     this.handleLog(LogLevel.WARN, args) |     this.handleLog(LogLevel.WARN, args) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   error(...args) { |   error(...args) { | ||||||
|     if (this.logLevel > LogLevel.ERROR) return |     if (this.logLevel > LogLevel.ERROR) return | ||||||
|     console.error(`[${this.timestamp}] ERROR:`, ...args) |     console.error(`[${this.timestamp}] ERROR:`, ...args, `(${this.source})`) | ||||||
|     this.handleLog(LogLevel.ERROR, args) |     this.handleLog(LogLevel.ERROR, args) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   fatal(...args) { |   fatal(...args) { | ||||||
|     console.error(`[${this.timestamp}] FATAL:`, ...args) |     console.error(`[${this.timestamp}] FATAL:`, ...args, `(${this.source})`) | ||||||
|     this.handleLog(LogLevel.FATAL, args) |     this.handleLog(LogLevel.FATAL, args) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -41,6 +41,7 @@ class Server { | |||||||
|     this.Port = PORT |     this.Port = PORT | ||||||
|     this.Host = HOST |     this.Host = HOST | ||||||
|     global.Source = SOURCE |     global.Source = SOURCE | ||||||
|  |     global.isWin = process.platform === 'win32' | ||||||
|     global.Uid = isNaN(UID) ? 0 : Number(UID) |     global.Uid = isNaN(UID) ? 0 : Number(UID) | ||||||
|     global.Gid = isNaN(GID) ? 0 : Number(GID) |     global.Gid = isNaN(GID) ? 0 : Number(GID) | ||||||
|     global.ConfigPath = Path.normalize(CONFIG_PATH) |     global.ConfigPath = Path.normalize(CONFIG_PATH) | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user