Replace LogLabelOrNull type with undefined

This commit is contained in:
RMidhunSuresh 2021-11-15 18:59:33 +05:30
parent 30a384fe1e
commit 7097ba07d1
7 changed files with 23 additions and 27 deletions

View file

@ -18,7 +18,6 @@ limitations under the License.
import {LogItem} from "./LogItem";
import {LogLevel, LogFilter} from "./LogFilter";
import type {FilterCreator, LabelOrValues, LogCallback, ILogItem} from "./LogItem";
import type {LogLevelOrNull} from "./LogFilter";
// todo: should this import be here just for getting the type? should it instead be done when Platform.js --> Platform.ts?
import type {Platform} from "../platform/web/Platform.js";
@ -38,7 +37,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. */
wrapOrRun(item: ILogItem, labelOrValues: LabelOrValues, callback: LogCallback, logLevel: LogLevelOrNull = null, filterCreator?: FilterCreator): unknown {
wrapOrRun(item: ILogItem, labelOrValues: LabelOrValues, callback: LogCallback, logLevel?: LogLevel, filterCreator?: FilterCreator): unknown {
if (item) {
return item.wrap(labelOrValues, callback, logLevel, filterCreator);
} else {
@ -51,9 +50,9 @@ export abstract class BaseLogger {
Useful to pair with LogItem.refDetached.
@return {LogItem} the log item added, useful to pass to LogItem.refDetached */
runDetached(labelOrValues: LabelOrValues, callback: LogCallback, logLevel: LogLevelOrNull = null, filterCreator?: FilterCreator): ILogItem {
runDetached(labelOrValues: LabelOrValues, callback: LogCallback, logLevel?: LogLevel, filterCreator?: FilterCreator): ILogItem {
// todo: Remove jsdoc type?
if (logLevel === null) {
if (!logLevel) {
logLevel = LogLevel.Info;
}
const item = new LogItem(labelOrValues, logLevel, this);
@ -64,8 +63,8 @@ export abstract class BaseLogger {
/** 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: LabelOrValues, callback: LogCallback, logLevel: LogLevelOrNull = null, filterCreator?: FilterCreator): unknown {
if (logLevel === null) {
run(labelOrValues: LabelOrValues, callback: LogCallback, logLevel?: LogLevel, filterCreator?: FilterCreator): unknown {
if (!logLevel) {
logLevel = LogLevel.Info;
}
const item = new LogItem(labelOrValues, logLevel, this);

View file

@ -40,6 +40,7 @@ export class IDBLogger extends BaseLogger {
private readonly _flushInterval: Interval;
private _queuedItems: QueuedItem[];
// todo: type constructor
constructor(options) {
super(options);
const {name, flushInterval = 60 * 1000, limit = 3000} = options;

View file

@ -27,8 +27,6 @@ export enum LogLevel {
Off
}
export type LogLevelOrNull = LogLevel | null;
export class LogFilter {
private _min?: LogLevel;
private _parentFilter?: LogFilter;

View file

@ -16,7 +16,6 @@ limitations under the License.
*/
import {LogLevel, LogFilter} from "./LogFilter";
import type {LogLevelOrNull} from "./LogFilter";
import type {BaseLogger} from "./BaseLogger";
interface ISerializedItem {
@ -43,17 +42,17 @@ export interface ILogItem {
children: Array<ILogItem> | null;
values: LogItemValues;
error: Error | null;
wrap(labelOrValues: LabelOrValues, callback: LogCallback, level: LogLevelOrNull, filterCreator?: FilterCreator): unknown;
log(labelOrValues: LabelOrValues, logLevel: LogLevelOrNull): void;
wrap(labelOrValues: LabelOrValues, callback: LogCallback, logLevel?: LogLevel, filterCreator?: FilterCreator): unknown;
log(labelOrValues: LabelOrValues, logLevel?: LogLevel): void;
set(key: string | object, value: unknown): void;
run(callback: LogCallback): unknown;
runDetached(labelOrValues: LabelOrValues, callback: LogCallback, logLevel: LogLevelOrNull, filterCreator: FilterCreator): ILogItem;
wrapDetached(labelOrValues: LabelOrValues, callback: LogCallback, logLevel: LogLevelOrNull, filterCreator: FilterCreator): void;
refDetached(logItem: ILogItem, logLevel: LogLevelOrNull): void;
runDetached(labelOrValues: LabelOrValues, callback: LogCallback, logLevel?: LogLevel, filterCreator?: FilterCreator): ILogItem;
wrapDetached(labelOrValues: LabelOrValues, callback: LogCallback, logLevel?: LogLevel, filterCreator?: FilterCreator): void;
refDetached(logItem: ILogItem, logLevel?: LogLevel): void;
ensureRefId(): void;
catch(err: Error): Error;
finish(): void;
child(labelOrValues: LabelOrValues, logLevel: LogLevelOrNull, filterCreator: FilterCreator): ILogItem;
child(labelOrValues: LabelOrValues, logLevel?: LogLevel, filterCreator?: FilterCreator): ILogItem;
serialize(filter: LogFilter, parentStartTime: number | null, forced: boolean): ISerializedItem | null;
}
@ -94,18 +93,18 @@ export class LogItem implements ILogItem {
}
/** start a new root log item and run it detached mode, see BaseLogger.runDetached */
runDetached(labelOrValues: LabelOrValues, callback: LogCallback, logLevel: LogLevelOrNull, filterCreator: FilterCreator): ILogItem {
runDetached(labelOrValues: LabelOrValues, callback: LogCallback, logLevel?: LogLevel, filterCreator?: FilterCreator): ILogItem {
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: LabelOrValues, callback: LogCallback, logLevel: LogLevelOrNull, filterCreator: FilterCreator): void {
wrapDetached(labelOrValues: LabelOrValues, callback: LogCallback, logLevel?: LogLevel, filterCreator?: FilterCreator): void {
this.refDetached(this.runDetached(labelOrValues, callback, logLevel, filterCreator));
}
/** logs a reference to a different log item, usually obtained from runDetached.
This is useful if the referenced operation can't be awaited. */
refDetached(logItem: ILogItem, logLevel: LogLevelOrNull = null): void {
refDetached(logItem: ILogItem, logLevel?: LogLevel): void {
logItem.ensureRefId();
this.log({ref: (logItem as LogItem)._values.refId}, logLevel);
}
@ -119,7 +118,7 @@ export class LogItem implements ILogItem {
/**
* Creates a new child item and runs it in `callback`.
*/
wrap(labelOrValues: LabelOrValues, callback: LogCallback, logLevel: LogLevelOrNull = null, filterCreator?: FilterCreator): unknown {
wrap(labelOrValues: LabelOrValues, callback: LogCallback, logLevel?: LogLevel, filterCreator?: FilterCreator): unknown {
const item = this.child(labelOrValues, logLevel, filterCreator);
return item.run(callback);
}
@ -160,7 +159,7 @@ export class LogItem implements ILogItem {
*
* Hence, the child item is not returned.
*/
log(labelOrValues: LabelOrValues, logLevel: LogLevelOrNull = null): void {
log(labelOrValues: LabelOrValues, logLevel?: LogLevel): void {
const item = this.child(labelOrValues, logLevel);
item.end = item.start;
}
@ -291,7 +290,7 @@ export class LogItem implements ILogItem {
return err;
}
child(labelOrValues: LabelOrValues, logLevel: LogLevelOrNull, filterCreator?: FilterCreator): ILogItem {
child(labelOrValues: LabelOrValues, logLevel?: LogLevel, filterCreator?: FilterCreator): ILogItem {
if (this.end !== null) {
console.trace("log item is finished, additional logs will likely not be recorded");
}

View file

@ -101,8 +101,7 @@ async function createStores(db: IDBDatabase, txn: IDBTransaction, oldVersion: nu
async (log) => {
for (let i = startIdx; i < version; ++i) {
const migrationFunc = schema[i];
await log.wrap(`v${i + 1}`, (log) => migrationFunc(db, txn, localStorage, log), null);
await log.wrap(`v${i + 1}`, (log) => migrationFunc(db, txn, localStorage, log));
}
},
null) as Promise<void>;
}) as Promise<void>;
}

View file

@ -226,7 +226,7 @@ export class Transaction {
};
const label = `${this._writeErrors.length} storage write operation(s) failed`;
if (parentItem) {
parentItem.wrap(label, callback, null);
parentItem.wrap(label, callback);
} else {
this.logger.run(label, callback);
}

View file

@ -196,7 +196,7 @@ async function fixMissingRoomsInUserIdentities(db: IDBDatabase, txn: IDBTransact
const updatedIdentity = addRoomToIdentity(identity, userId, roomId);
if (updatedIdentity) {
log.log({l: `fixing up`, id: userId,
roomsBefore: originalRoomCount, roomsAfter: updatedIdentity.roomIds.length}, null);
roomsBefore: originalRoomCount, roomsAfter: updatedIdentity.roomIds.length});
userIdentitiesStore.put(updatedIdentity);
foundMissing = true;
}
@ -207,7 +207,7 @@ async function fixMissingRoomsInUserIdentities(db: IDBDatabase, txn: IDBTransact
// so we'll create a new one on the next message that will be properly shared
outboundGroupSessionsStore.delete(roomId);
}
}, null);
});
}
}