From e96bc9c48a576e0f0ba51a6bf45233c335759fa2 Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Sat, 11 May 2019 17:53:56 +0100 Subject: [PATCH] All: Allow specifying the log level of a log target --- ReactNativeClient/lib/BaseApplication.js | 2 +- ReactNativeClient/lib/logger.js | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ReactNativeClient/lib/BaseApplication.js b/ReactNativeClient/lib/BaseApplication.js index 0faf209b62..98bac42db3 100644 --- a/ReactNativeClient/lib/BaseApplication.js +++ b/ReactNativeClient/lib/BaseApplication.js @@ -534,7 +534,7 @@ class BaseApplication { initArgs = Object.assign(initArgs, extraFlags); this.logger_.addTarget('file', { path: profileDir + '/log.txt' }); - // if (Setting.value('env') === 'dev') this.logger_.addTarget('console'); + if (Setting.value('env') === 'dev') this.logger_.addTarget('console', { level: Logger.LEVEL_WARN }); this.logger_.setLevel(initArgs.logLevel); reg.setLogger(this.logger_); diff --git a/ReactNativeClient/lib/logger.js b/ReactNativeClient/lib/logger.js index a370fd72c0..41f84f6cc9 100644 --- a/ReactNativeClient/lib/logger.js +++ b/ReactNativeClient/lib/logger.js @@ -101,8 +101,13 @@ class Logger { return []; } + targetLevel(target) { + if ('level' in target) return target.level; + return this.level(); + } + log(level, ...object) { - if (this.level() < level || !this.targets_.length) return; + if (!this.targets_.length) return; let levelString = ''; let line = moment().format('YYYY-MM-DD HH:mm:ss') + ': '; @@ -112,6 +117,9 @@ class Logger { for (let i = 0; i < this.targets_.length; i++) { let target = this.targets_[i]; + + if (this.targetLevel(target) < level) continue; + if (target.type == 'console') { let fn = 'log'; if (level == Logger.LEVEL_ERROR) fn = 'error';