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