forked from mystiq/hydrogen-web
some doc comments for logging api
This commit is contained in:
parent
dd38fc13d7
commit
7b7907add0
2 changed files with 17 additions and 4 deletions
|
@ -29,6 +29,7 @@ export class BaseLogger {
|
|||
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) {
|
||||
if (item) {
|
||||
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) {
|
||||
if (logLevel === null) {
|
||||
logLevel = LogLevel.Info;
|
||||
|
@ -48,6 +54,9 @@ export class BaseLogger {
|
|||
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) {
|
||||
if (logLevel === null) {
|
||||
logLevel = LogLevel.Info;
|
||||
|
|
|
@ -29,14 +29,22 @@ export class LogItem {
|
|||
this._filterCreator = filterCreator;
|
||||
}
|
||||
|
||||
/** start a new root log item and run it detached mode, see BaseLogger.runDetached */
|
||||
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) {
|
||||
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`.
|
||||
*/
|
||||
|
@ -80,10 +88,6 @@ export class LogItem {
|
|||
item._end = item._start;
|
||||
}
|
||||
|
||||
refDetached(logItem, logLevel = null) {
|
||||
return this.log({ref: logItem._values.refId}, logLevel);
|
||||
}
|
||||
|
||||
set(key, value) {
|
||||
if(typeof key === "object") {
|
||||
const values = key;
|
||||
|
|
Loading…
Reference in a new issue