mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 11:35:04 +01:00
some doc comments for logging api
This commit is contained in:
parent
dd38fc13d7
commit
7b7907add0
@ -29,6 +29,7 @@ export class BaseLogger {
|
|||||||
this._persistItem(item.serialize(null));
|
this._persistItem(item.serialize(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** if item is a log item, wrap the callback in a child of it, otherwise start a new root log item. */
|
||||||
wrapOrRun(item, labelOrValues, callback, logLevel = null, filterCreator = null) {
|
wrapOrRun(item, labelOrValues, callback, logLevel = null, filterCreator = null) {
|
||||||
if (item) {
|
if (item) {
|
||||||
return item.wrap(labelOrValues, callback, logLevel, filterCreator);
|
return item.wrap(labelOrValues, callback, logLevel, filterCreator);
|
||||||
@ -37,6 +38,11 @@ export class BaseLogger {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** run a callback in detached mode,
|
||||||
|
where the (async) result or errors are not propagated but still logged.
|
||||||
|
Useful to pair with LogItem.refDetached.
|
||||||
|
|
||||||
|
@return {LogItem} the log item added, useful to pass to LogItem.refDetached */
|
||||||
runDetached(labelOrValues, callback, logLevel = null, filterCreator = null) {
|
runDetached(labelOrValues, callback, logLevel = null, filterCreator = null) {
|
||||||
if (logLevel === null) {
|
if (logLevel === null) {
|
||||||
logLevel = LogLevel.Info;
|
logLevel = LogLevel.Info;
|
||||||
@ -48,6 +54,9 @@ export class BaseLogger {
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** run a callback wrapped in a log operation.
|
||||||
|
Errors and duration are transparently logged, also for async operations.
|
||||||
|
Whatever the callback returns is returned here. */
|
||||||
run(labelOrValues, callback, logLevel = null, filterCreator = null) {
|
run(labelOrValues, callback, logLevel = null, filterCreator = null) {
|
||||||
if (logLevel === null) {
|
if (logLevel === null) {
|
||||||
logLevel = LogLevel.Info;
|
logLevel = LogLevel.Info;
|
||||||
|
@ -29,14 +29,22 @@ export class LogItem {
|
|||||||
this._filterCreator = filterCreator;
|
this._filterCreator = filterCreator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** start a new root log item and run it detached mode, see BaseLogger.runDetached */
|
||||||
runDetached(labelOrValues, callback, logLevel, filterCreator) {
|
runDetached(labelOrValues, callback, logLevel, filterCreator) {
|
||||||
return this._logger.runDetached(labelOrValues, callback, logLevel, filterCreator);
|
return this._logger.runDetached(labelOrValues, callback, logLevel, filterCreator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** start a new detached root log item and log a reference to it from this item */
|
||||||
wrapDetached(labelOrValues, callback, logLevel, filterCreator) {
|
wrapDetached(labelOrValues, callback, logLevel, filterCreator) {
|
||||||
this.refDetached(this.runDetached(labelOrValues, callback, logLevel, filterCreator));
|
this.refDetached(this.runDetached(labelOrValues, callback, logLevel, filterCreator));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** logs a reference to a different log item, obtained from runDetached.
|
||||||
|
This is useful if the referenced operation can't be awaited. */
|
||||||
|
refDetached(logItem, logLevel = null) {
|
||||||
|
return this.log({ref: logItem._values.refId}, logLevel);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new child item and runs it in `callback`.
|
* Creates a new child item and runs it in `callback`.
|
||||||
*/
|
*/
|
||||||
@ -80,10 +88,6 @@ export class LogItem {
|
|||||||
item._end = item._start;
|
item._end = item._start;
|
||||||
}
|
}
|
||||||
|
|
||||||
refDetached(logItem, logLevel = null) {
|
|
||||||
return this.log({ref: logItem._values.refId}, logLevel);
|
|
||||||
}
|
|
||||||
|
|
||||||
set(key, value) {
|
set(key, value) {
|
||||||
if(typeof key === "object") {
|
if(typeof key === "object") {
|
||||||
const values = key;
|
const values = key;
|
||||||
|
Loading…
Reference in New Issue
Block a user