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.
This commit is contained in:
Bruno Windels 2021-02-17 17:13:06 +01:00
parent e9ce87ed9b
commit d201d2c9de
4 changed files with 22 additions and 28 deletions

View File

@ -40,7 +40,7 @@ export class BaseLogger {
filter = filter.minLevel(logLevel); filter = filter.minLevel(logLevel);
} }
try { try {
const serialized = item.serialize(filter, 0); const serialized = item.serialize(filter);
if (serialized) { if (serialized) {
this._persistItem(serialized); this._persistItem(serialized);
} }

View File

@ -17,31 +17,29 @@ limitations under the License.
export const LogLevel = { export const LogLevel = {
All: 1, All: 1,
Debug: 2, Debug: 2,
Info: 3, Detail: 3,
Warn: 4, Info: 4,
Error: 5, Warn: 5,
Fatal: 6, Error: 6,
Off: 7, Fatal: 7,
Off: 8,
} }
export class LogFilter { export class LogFilter {
constructor(parentFilter) { constructor(parentFilter) {
this._parentFilter = parentFilter; this._parentFilter = parentFilter;
this._min = null; this._min = null;
this._maxDepth = null;
} }
filter(item, children, depth) { filter(item, children) {
if (this._parentFilter) { if (this._parentFilter) {
if (!this._parentFilter.filter(item, children, depth)) { if (!this._parentFilter.filter(item, children)) {
return false; return false;
} }
} }
// neither our children or us have a loglevel high enough, filter out. // neither our children or us have a loglevel high enough, filter out.
if (this._min !== null && children === null && item.logLevel < this._min) { if (this._min !== null && children === null && item.logLevel < this._min) {
return false; return false;
} if (this._maxDepth !== null && depth > this._maxDepth) {
return false;
} else { } else {
return true; return true;
} }
@ -52,9 +50,4 @@ export class LogFilter {
this._min = logLevel; this._min = logLevel;
return this; return this;
} }
maxDepth(depth) {
this._maxDepth = depth;
return this;
}
} }

View File

@ -65,7 +65,7 @@ export class LogItem {
} }
} }
serialize(filter, depth) { serialize(filter) {
if (this._filterCreator) { if (this._filterCreator) {
try { try {
filter = this._filterCreator(new LogFilter(filter), this); filter = this._filterCreator(new LogFilter(filter), this);
@ -76,7 +76,7 @@ export class LogItem {
let children; let children;
if (this._children !== null) { if (this._children !== null) {
children = this._children.reduce((array, c) => { children = this._children.reduce((array, c) => {
const s = c.serialize(filter, depth + 1); const s = c.serialize(filter);
if (s) { if (s) {
if (array === null) { if (array === null) {
array = []; array = [];
@ -86,7 +86,7 @@ export class LogItem {
return array; return array;
}, null); }, null);
} }
if (!filter.filter(this, children, depth)) { if (!filter.filter(this, children)) {
return null; return null;
} }
const item = { const item = {

View File

@ -90,6 +90,14 @@ export class Sync {
this._syncLoop(syncToken); 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) { async _syncLoop(syncToken) {
// if syncToken is falsy, it will first do an initial sync ... // if syncToken is falsy, it will first do an initial sync ...
while(this._status.get() !== SyncStatus.Stopped) { while(this._status.get() !== SyncStatus.Stopped) {
@ -112,15 +120,8 @@ export class Sync {
const syncResult = await this._logger.run("sync", const syncResult = await this._logger.run("sync",
log => this._syncRequest(syncToken, timeout, log), log => this._syncRequest(syncToken, timeout, log),
this._logger.level.Info, this._logger.level.Info,
(filter, log) => { this._createLogFilter.bind(this)
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);
}
});
syncToken = syncResult.syncToken; syncToken = syncResult.syncToken;
roomStates = syncResult.roomStates; roomStates = syncResult.roomStates;
sessionChanges = syncResult.sessionChanges; sessionChanges = syncResult.sessionChanges;