From 2dd8803efc9c2ab60b6d0061dfdda83c11646680 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Tue, 16 Feb 2021 18:30:23 +0100 Subject: [PATCH] better error handling if something goes wrong serializing log items --- src/logging/BaseLogger.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/logging/BaseLogger.js b/src/logging/BaseLogger.js index 01e9899d..abf330b3 100644 --- a/src/logging/BaseLogger.js +++ b/src/logging/BaseLogger.js @@ -35,9 +35,13 @@ export class BaseLogger { // if not filter is specified, filter out anything lower than the initial log level filter = filter.minLevel(logLevel); } - const serialized = item.serialize(filter, 0); - if (serialized) { - this._persistItem(serialized); + try { + const serialized = item.serialize(filter, 0); + if (serialized) { + this._persistItem(serialized); + } + } catch (err) { + console.warn("Could not serialize log item", err); } this._openItems.delete(item); }; @@ -65,9 +69,13 @@ export class BaseLogger { _finishOpenItems() { for (const openItem of this._openItems) { openItem.finish(); - const serialized = openItem.serialize(this._baseLogLevel); - if (serialized) { - this._persistItem(serialized); + try { + const serialized = openItem.serialize(this._baseLogLevel); + if (serialized) { + this._persistItem(serialized); + } + } catch (err) { + console.warn("Could not serialize log item", err); } } this._openItems.clear();