forked from mystiq/hydrogen-web
Annotate method arguments
This commit is contained in:
parent
7893a121c0
commit
8cbc81b8bb
1 changed files with 10 additions and 6 deletions
|
@ -21,6 +21,10 @@ import {Platform} from "../platform/web/Platform.js";
|
||||||
|
|
||||||
// todo: move this to LogItem?
|
// todo: move this to LogItem?
|
||||||
type LabelOrValues = string | {l: string; [key: string]: unknown};
|
type LabelOrValues = string | {l: string; [key: string]: unknown};
|
||||||
|
type LogCallback = (item: LogItem) => Promise<unknown> | undefined;
|
||||||
|
// todo: this should be an enum
|
||||||
|
type LogLevel = number | null;
|
||||||
|
type FilterCreator = ((filter: LogFilter, item: LogItem) => LogFilter) | null;
|
||||||
|
|
||||||
export abstract class BaseLogger {
|
export abstract class BaseLogger {
|
||||||
protected _openItems: Set<LogItem> = new Set();
|
protected _openItems: Set<LogItem> = new Set();
|
||||||
|
@ -37,7 +41,7 @@ export abstract class BaseLogger {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 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: LabelOrValues, callback, logLevel = null, filterCreator = null) {
|
wrapOrRun(item: LogItem, labelOrValues: LabelOrValues, callback: LogCallback, logLevel: LogLevel = null, filterCreator: FilterCreator = null) {
|
||||||
if (item) {
|
if (item) {
|
||||||
return item.wrap(labelOrValues, callback, logLevel, filterCreator);
|
return item.wrap(labelOrValues, callback, logLevel, filterCreator);
|
||||||
} else {
|
} else {
|
||||||
|
@ -50,27 +54,27 @@ 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: LabelOrValues, callback, logLevel = null, filterCreator = null) {
|
runDetached(labelOrValues: LabelOrValues, callback: LogCallback, logLevel: LogLevel = null, filterCreator: FilterCreator = null) {
|
||||||
if (logLevel === null) {
|
if (logLevel === null) {
|
||||||
logLevel = LogLevel.Info;
|
logLevel = LogLevel.Info;
|
||||||
}
|
}
|
||||||
const item = new LogItem(labelOrValues, logLevel, null, this);
|
const item = new LogItem(labelOrValues, logLevel, null, this);
|
||||||
this._run(item, callback, logLevel, filterCreator, false /* don't throw, nobody is awaiting */);
|
this._run(item, callback, logLevel!, filterCreator, false /* don't throw, nobody is awaiting */);
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 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: LabelOrValues, callback, logLevel = null, filterCreator = null) {
|
run(labelOrValues: LabelOrValues, callback: LogCallback, logLevel: LogLevel = null, filterCreator: FilterCreator = null) {
|
||||||
if (logLevel === null) {
|
if (logLevel === null) {
|
||||||
logLevel = LogLevel.Info;
|
logLevel = LogLevel.Info;
|
||||||
}
|
}
|
||||||
const item = new LogItem(labelOrValues, logLevel, null, this);
|
const item = new LogItem(labelOrValues, logLevel, null, this);
|
||||||
return this._run(item, callback, logLevel, filterCreator, true);
|
return this._run(item, callback, logLevel!, filterCreator, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
_run(item, callback, logLevel, filterCreator, shouldThrow) {
|
_run(item: LogItem, callback: LogCallback, logLevel: number, filterCreator: FilterCreator, shouldThrow: boolean) {
|
||||||
this._openItems.add(item);
|
this._openItems.add(item);
|
||||||
|
|
||||||
const finishItem = () => {
|
const finishItem = () => {
|
||||||
|
|
Loading…
Reference in a new issue