Convert NullLogger to typescript

This commit is contained in:
RMidhunSuresh 2021-11-16 12:23:06 +05:30
parent 4c1d7a8f2d
commit 4161d31642

View file

@ -18,21 +18,20 @@ import type {ILogItem, LabelOrValues, LogCallback, LogItemValues} from "./LogIte
function noop (): void {} function noop (): void {}
export class NullLogger { export class NullLogger {
public readonly item: ILogItem = new NullLogItem(this); public readonly item: ILogItem = new NullLogItem(this);
log(): void {} log(): void {}
run(_: null, callback) { run<T>(_, callback: LogCallback<T>): T | Promise<T> {
return callback(this.item); return callback(this.item);
} }
wrapOrRun(item, _, callback) { wrapOrRun<T>(item: ILogItem, _, callback: LogCallback<T>): T | Promise<T> {
if (item) { if (item) {
return item.wrap(null, callback); return item.wrap(_, callback);
} else { } else {
return this.run(null, callback); return this.run(_, callback);
} }
} }
@ -40,11 +39,11 @@ export class NullLogger {
new Promise(r => r(callback(this.item))).then(noop, noop); new Promise(r => r(callback(this.item))).then(noop, noop);
} }
async export() { async export(): Promise<null> {
return null; return null;
} }
get level() { get level(): typeof LogLevel {
return LogLevel; return LogLevel;
} }
} }
@ -63,6 +62,7 @@ export class NullLogItem implements ILogItem {
wrap<T>(_: LabelOrValues, callback: LogCallback<T>): T | Promise<T> { wrap<T>(_: LabelOrValues, callback: LogCallback<T>): T | Promise<T> {
return callback(this); return callback(this);
} }
log(): void {} log(): void {}
set(): void {} set(): void {}
@ -95,13 +95,13 @@ export class NullLogItem implements ILogItem {
return err; return err;
} }
child() { child(): ILogItem {
return this; return this;
} }
finish(): void {} finish(): void {}
serialize() { serialize(): undefined {
return undefined; return undefined;
} }
} }