annotate labelOrValues

This commit is contained in:
RMidhunSuresh 2021-11-09 17:19:46 +05:30
parent 839d3fb689
commit eef116e26b

View file

@ -19,6 +19,9 @@ import {LogItem} from "./LogItem.js";
import {LogLevel, LogFilter} from "./LogFilter.js"; import {LogLevel, LogFilter} from "./LogFilter.js";
import {Platform} from "../platform/web/Platform.js"; import {Platform} from "../platform/web/Platform.js";
// todo: move this to LogItem?
type LabelOrValues = string | {l: string; [key: string]: any};
export abstract class BaseLogger { export abstract class BaseLogger {
protected _openItems: Set<LogItem>; protected _openItems: Set<LogItem>;
protected _platform: Platform; protected _platform: Platform;
@ -28,14 +31,14 @@ export abstract class BaseLogger {
this._platform = platform; this._platform = platform;
} }
log(labelOrValues, logLevel = LogLevel.Info) { log(labelOrValues: LabelOrValues, logLevel: number = LogLevel.Info) {
const item = new LogItem(labelOrValues, logLevel, null, this); const item = new LogItem(labelOrValues, logLevel, null, this);
item._end = item._start; item._end = item._start;
this._persistItem(item, null, false); this._persistItem(item, null, false);
} }
/** if item is a log item, wrap the callback in a child of it, otherwise start a new root log item. */ /** 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: LabelOrValues, callback, logLevel = null, filterCreator = null) {
if (item) { if (item) {
return item.wrap(labelOrValues, callback, logLevel, filterCreator); return item.wrap(labelOrValues, callback, logLevel, filterCreator);
} else { } else {
@ -48,7 +51,7 @@ export abstract class BaseLogger {
Useful to pair with LogItem.refDetached. Useful to pair with LogItem.refDetached.
@return {LogItem} the log item added, useful to pass to LogItem.refDetached */ @return {LogItem} the log item added, useful to pass to LogItem.refDetached */
runDetached(labelOrValues, callback, logLevel = null, filterCreator = null) { runDetached(labelOrValues: LabelOrValues, callback, logLevel = null, filterCreator = null) {
if (logLevel === null) { if (logLevel === null) {
logLevel = LogLevel.Info; logLevel = LogLevel.Info;
} }
@ -60,7 +63,7 @@ export abstract class BaseLogger {
/** run a callback wrapped in a log operation. /** run a callback wrapped in a log operation.
Errors and duration are transparently logged, also for async operations. Errors and duration are transparently logged, also for async operations.
Whatever the callback returns is returned here. */ Whatever the callback returns is returned here. */
run(labelOrValues, callback, logLevel = null, filterCreator = null) { run(labelOrValues: LabelOrValues, callback, logLevel = null, filterCreator = null) {
if (logLevel === null) { if (logLevel === null) {
logLevel = LogLevel.Info; logLevel = LogLevel.Info;
} }