1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-11-27 08:21:03 +02:00

All: Allow specifying the log level of a log target

This commit is contained in:
Laurent Cozic 2019-05-11 17:53:56 +01:00
parent 0d036d8183
commit e96bc9c48a
2 changed files with 10 additions and 2 deletions

View File

@ -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_);

View File

@ -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';