From d201d2c9de27cf2f0467463b51801bfbfaf5967c Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 17 Feb 2021 17:13:06 +0100 Subject: [PATCH] don't use depth based log filtering, also add Detail log level it's hard to make it work with an override where you don't want to filter by depth if a given loglevel is present in the children. --- src/logging/BaseLogger.js | 2 +- src/logging/LogFilter.js | 23 ++++++++--------------- src/logging/LogItem.js | 6 +++--- src/matrix/Sync.js | 19 ++++++++++--------- 4 files changed, 22 insertions(+), 28 deletions(-) diff --git a/src/logging/BaseLogger.js b/src/logging/BaseLogger.js index 44410220..ea935a8f 100644 --- a/src/logging/BaseLogger.js +++ b/src/logging/BaseLogger.js @@ -40,7 +40,7 @@ export class BaseLogger { filter = filter.minLevel(logLevel); } try { - const serialized = item.serialize(filter, 0); + const serialized = item.serialize(filter); if (serialized) { this._persistItem(serialized); } diff --git a/src/logging/LogFilter.js b/src/logging/LogFilter.js index 461a3e86..c889df9b 100644 --- a/src/logging/LogFilter.js +++ b/src/logging/LogFilter.js @@ -17,31 +17,29 @@ limitations under the License. export const LogLevel = { All: 1, Debug: 2, - Info: 3, - Warn: 4, - Error: 5, - Fatal: 6, - Off: 7, + Detail: 3, + Info: 4, + Warn: 5, + Error: 6, + Fatal: 7, + Off: 8, } export class LogFilter { constructor(parentFilter) { this._parentFilter = parentFilter; this._min = null; - this._maxDepth = null; } - filter(item, children, depth) { + filter(item, children) { if (this._parentFilter) { - if (!this._parentFilter.filter(item, children, depth)) { + if (!this._parentFilter.filter(item, children)) { return false; } } // neither our children or us have a loglevel high enough, filter out. if (this._min !== null && children === null && item.logLevel < this._min) { return false; - } if (this._maxDepth !== null && depth > this._maxDepth) { - return false; } else { return true; } @@ -52,9 +50,4 @@ export class LogFilter { this._min = logLevel; return this; } - - maxDepth(depth) { - this._maxDepth = depth; - return this; - } } diff --git a/src/logging/LogItem.js b/src/logging/LogItem.js index 54eb51c2..ac376e5e 100644 --- a/src/logging/LogItem.js +++ b/src/logging/LogItem.js @@ -65,7 +65,7 @@ export class LogItem { } } - serialize(filter, depth) { + serialize(filter) { if (this._filterCreator) { try { filter = this._filterCreator(new LogFilter(filter), this); @@ -76,7 +76,7 @@ export class LogItem { let children; if (this._children !== null) { children = this._children.reduce((array, c) => { - const s = c.serialize(filter, depth + 1); + const s = c.serialize(filter); if (s) { if (array === null) { array = []; @@ -86,7 +86,7 @@ export class LogItem { return array; }, null); } - if (!filter.filter(this, children, depth)) { + if (!filter.filter(this, children)) { return null; } const item = { diff --git a/src/matrix/Sync.js b/src/matrix/Sync.js index 454c7435..56aa4469 100644 --- a/src/matrix/Sync.js +++ b/src/matrix/Sync.js @@ -90,6 +90,14 @@ export class Sync { this._syncLoop(syncToken); } + _createLogFilter(filter, log) { + if (log.duration >= 2000 || log.error || this._status.get() === SyncStatus.CatchupSync) { + return filter.minLevel(log.level.Detail); + } else { + return filter.minLevel(log.level.Info); + } + } + async _syncLoop(syncToken) { // if syncToken is falsy, it will first do an initial sync ... while(this._status.get() !== SyncStatus.Stopped) { @@ -112,15 +120,8 @@ export class Sync { const syncResult = await this._logger.run("sync", log => this._syncRequest(syncToken, timeout, log), this._logger.level.Info, - (filter, log) => { - if (log.duration >= 2000 || this._status.get() === SyncStatus.CatchupSync) { - return filter.minLevel(log.level.Info); - } else if (log.error) { - return filter.minLevel(log.level.Error); - } else { - return filter.maxDepth(0); - } - }); + this._createLogFilter.bind(this) + ); syncToken = syncResult.syncToken; roomStates = syncResult.roomStates; sessionChanges = syncResult.sessionChanges;