only create refids when used

This commit is contained in:
Bruno Windels 2021-02-24 10:14:14 +01:00
parent 86011b42e3
commit a372836a64
2 changed files with 8 additions and 3 deletions

View File

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

View File

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