ensure any breakage does not disrupt logging

This commit is contained in:
Bruno Windels 2021-02-16 18:36:41 +01:00
parent 2dd8803efc
commit c3637def2e
3 changed files with 14 additions and 6 deletions

View File

@ -30,7 +30,11 @@ export class BaseLogger {
const finishItem = () => {
let filter = new LogFilter();
if (filterCreator) {
filter = filterCreator(filter, this);
try {
filter = filterCreator(filter, this);
} catch (err) {
console.error("Error while creating log filter", err);
}
} else {
// if not filter is specified, filter out anything lower than the initial log level
filter = filter.minLevel(logLevel);
@ -41,7 +45,7 @@ export class BaseLogger {
this._persistItem(serialized);
}
} catch (err) {
console.warn("Could not serialize log item", err);
console.error("Could not serialize log item", err);
}
this._openItems.delete(item);
};
@ -75,7 +79,7 @@ export class BaseLogger {
this._persistItem(serialized);
}
} catch (err) {
console.warn("Could not serialize log item", err);
console.error("Could not serialize log item", err);
}
}
this._openItems.clear();

View File

@ -72,7 +72,7 @@ export class IDBLogger extends BaseLogger {
await txnAsPromise(txn);
this._queuedItems.splice(0, amount);
} catch (err) {
console.warn("Could not flush logs", err);
console.error("Could not flush logs", err);
} finally {
try {
db.close();
@ -113,7 +113,7 @@ export class IDBLogger extends BaseLogger {
try {
window.localStorage.setItem(`${this._name}_queuedItems`, JSON.stringify(items));
} catch (e) {
console.warn("Could not persist queued log items in localStorage, they will likely be lost", e);
console.error("Could not persist queued log items in localStorage, they will likely be lost", e);
}
}

View File

@ -66,7 +66,11 @@ export class LogItem {
serialize(filter, depth) {
if (this._filterCreator) {
filter = this._filterCreator(new LogFilter(filter), this);
try {
filter = this._filterCreator(new LogFilter(filter), this);
} catch (err) {
console.error("Error creating log item", err);
}
}
let children;
if (this._children !== null) {