diff --git a/server/Logger.js b/server/Logger.js index b49531893..0c498ec1f 100644 --- a/server/Logger.js +++ b/server/Logger.js @@ -5,7 +5,16 @@ class Logger { constructor() { this.isDev = process.env.NODE_ENV !== 'production' this.logLevel = !this.isDev ? LogLevel.INFO : LogLevel.TRACE - this.hideDevLogs = process.env.HIDE_DEV_LOGS === undefined ? !this.isDev : process.env.HIDE_DEV_LOGS === '1' + + // Allow the user to override the log level if desired + if (process.env.LOG_LEVEL) { + this.logLevel = parseInt(LogLevel.strToLevel(process.env.LOG_LEVEL)) + } else { + this.hideDevLogs = process.env.HIDE_DEV_LOGS === undefined + ? !this.isDev + : process.env.HIDE_DEV_LOGS === '1' + } + this.socketListeners = [] this.logManager = null @@ -137,4 +146,4 @@ class Logger { this.handleLog(LogLevel.NOTE, args) } } -module.exports = new Logger() \ No newline at end of file +module.exports = new Logger() diff --git a/server/utils/constants.js b/server/utils/constants.js index 7a21d2ddc..193172f6e 100644 --- a/server/utils/constants.js +++ b/server/utils/constants.js @@ -23,7 +23,28 @@ module.exports.LogLevel = { WARN: 3, ERROR: 4, FATAL: 5, - NOTE: 6 + NOTE: 6, + + strToLevel(str) { + switch (str.toUpperCase()) { + case 'TRACE': + return this.TRACE + case 'DEBUG': + return this.DEBUG + case 'INFO': + return this.INFO + case 'WARN': + return this.WARN + case 'ERROR': + return this.ERROR + case 'FATAL': + return this.FATAL + case 'NOTE': + return this.NOTE + default: + return this.INFO + } + } } module.exports.PlayMethod = { @@ -54,4 +75,4 @@ module.exports.AudioMimeType = { module.exports.VideoMimeType = { MP4: 'video/mp4' -} \ No newline at end of file +}