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);
}
try {
const serialized = item.serialize(filter, 0);
const serialized = item.serialize(filter);
if (serialized) {
this._persistItem(serialized);
}

View file

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

View file

@ -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 = {

View file

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