From a372836a64c59b8d853fc1c81af1a7adaf805a9a Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 24 Feb 2021 10:14:14 +0100 Subject: [PATCH] only create refids when used --- src/logging/BaseLogger.js | 6 ++++-- src/logging/LogItem.js | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/logging/BaseLogger.js b/src/logging/BaseLogger.js index 063bea31..1d231b90 100644 --- a/src/logging/BaseLogger.js +++ b/src/logging/BaseLogger.js @@ -48,8 +48,6 @@ export class BaseLogger { logLevel = LogLevel.Info; } const item = new LogItem(labelOrValues, logLevel, null, this); - const refId = Math.round(this._platform.random() * Number.MAX_SAFE_INTEGER); - item.set("refId", refId); this._run(item, callback, logLevel, filterCreator, false /* don't throw, nobody is awaiting */); return item; } @@ -150,4 +148,8 @@ export class BaseLogger { _now() { return this._platform.clock.now(); } + + _createRefId() { + return Math.round(this._platform.random() * Number.MAX_SAFE_INTEGER); + } } diff --git a/src/logging/LogItem.js b/src/logging/LogItem.js index 203c788c..e699a4ac 100644 --- a/src/logging/LogItem.js +++ b/src/logging/LogItem.js @@ -39,9 +39,12 @@ export class LogItem { this.refDetached(this.runDetached(labelOrValues, callback, logLevel, filterCreator)); } - /** logs a reference to a different log item, obtained from runDetached. + /** logs a reference to a different log item, usually obtained from runDetached. This is useful if the referenced operation can't be awaited. */ refDetached(logItem, logLevel = null) { + if (!logItem._values.refId) { + logItem.set("refId", this._logger._createRefId()); + } return this.log({ref: logItem._values.refId}, logLevel); }