mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 19:45:05 +01:00
Replace LogLabelOrNull type with undefined
This commit is contained in:
parent
30a384fe1e
commit
7097ba07d1
@ -18,7 +18,6 @@ limitations under the License.
|
|||||||
import {LogItem} from "./LogItem";
|
import {LogItem} from "./LogItem";
|
||||||
import {LogLevel, LogFilter} from "./LogFilter";
|
import {LogLevel, LogFilter} from "./LogFilter";
|
||||||
import type {FilterCreator, LabelOrValues, LogCallback, ILogItem} from "./LogItem";
|
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?
|
// 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";
|
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. */
|
/** 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) {
|
if (item) {
|
||||||
return item.wrap(labelOrValues, callback, logLevel, filterCreator);
|
return item.wrap(labelOrValues, callback, logLevel, filterCreator);
|
||||||
} else {
|
} else {
|
||||||
@ -51,9 +50,9 @@ 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: LogCallback, logLevel: LogLevelOrNull = null, filterCreator?: FilterCreator): ILogItem {
|
runDetached(labelOrValues: LabelOrValues, callback: LogCallback, logLevel?: LogLevel, filterCreator?: FilterCreator): ILogItem {
|
||||||
// todo: Remove jsdoc type?
|
// todo: Remove jsdoc type?
|
||||||
if (logLevel === null) {
|
if (!logLevel) {
|
||||||
logLevel = LogLevel.Info;
|
logLevel = LogLevel.Info;
|
||||||
}
|
}
|
||||||
const item = new LogItem(labelOrValues, logLevel, this);
|
const item = new LogItem(labelOrValues, logLevel, this);
|
||||||
@ -64,8 +63,8 @@ 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: LabelOrValues, callback: LogCallback, logLevel: LogLevelOrNull = null, filterCreator?: FilterCreator): unknown {
|
run(labelOrValues: LabelOrValues, callback: LogCallback, logLevel?: LogLevel, filterCreator?: FilterCreator): unknown {
|
||||||
if (logLevel === null) {
|
if (!logLevel) {
|
||||||
logLevel = LogLevel.Info;
|
logLevel = LogLevel.Info;
|
||||||
}
|
}
|
||||||
const item = new LogItem(labelOrValues, logLevel, this);
|
const item = new LogItem(labelOrValues, logLevel, this);
|
||||||
|
@ -40,6 +40,7 @@ export class IDBLogger extends BaseLogger {
|
|||||||
private readonly _flushInterval: Interval;
|
private readonly _flushInterval: Interval;
|
||||||
private _queuedItems: QueuedItem[];
|
private _queuedItems: QueuedItem[];
|
||||||
|
|
||||||
|
// todo: type constructor
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
super(options);
|
super(options);
|
||||||
const {name, flushInterval = 60 * 1000, limit = 3000} = options;
|
const {name, flushInterval = 60 * 1000, limit = 3000} = options;
|
||||||
|
@ -27,8 +27,6 @@ export enum LogLevel {
|
|||||||
Off
|
Off
|
||||||
}
|
}
|
||||||
|
|
||||||
export type LogLevelOrNull = LogLevel | null;
|
|
||||||
|
|
||||||
export class LogFilter {
|
export class LogFilter {
|
||||||
private _min?: LogLevel;
|
private _min?: LogLevel;
|
||||||
private _parentFilter?: LogFilter;
|
private _parentFilter?: LogFilter;
|
||||||
|
@ -16,7 +16,6 @@ limitations under the License.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {LogLevel, LogFilter} from "./LogFilter";
|
import {LogLevel, LogFilter} from "./LogFilter";
|
||||||
import type {LogLevelOrNull} from "./LogFilter";
|
|
||||||
import type {BaseLogger} from "./BaseLogger";
|
import type {BaseLogger} from "./BaseLogger";
|
||||||
|
|
||||||
interface ISerializedItem {
|
interface ISerializedItem {
|
||||||
@ -43,17 +42,17 @@ export interface ILogItem {
|
|||||||
children: Array<ILogItem> | null;
|
children: Array<ILogItem> | null;
|
||||||
values: LogItemValues;
|
values: LogItemValues;
|
||||||
error: Error | null;
|
error: Error | null;
|
||||||
wrap(labelOrValues: LabelOrValues, callback: LogCallback, level: LogLevelOrNull, filterCreator?: FilterCreator): unknown;
|
wrap(labelOrValues: LabelOrValues, callback: LogCallback, logLevel?: LogLevel, filterCreator?: FilterCreator): unknown;
|
||||||
log(labelOrValues: LabelOrValues, logLevel: LogLevelOrNull): void;
|
log(labelOrValues: LabelOrValues, logLevel?: LogLevel): void;
|
||||||
set(key: string | object, value: unknown): void;
|
set(key: string | object, value: unknown): void;
|
||||||
run(callback: LogCallback): unknown;
|
run(callback: LogCallback): unknown;
|
||||||
runDetached(labelOrValues: LabelOrValues, callback: LogCallback, logLevel: LogLevelOrNull, filterCreator: FilterCreator): ILogItem;
|
runDetached(labelOrValues: LabelOrValues, callback: LogCallback, logLevel?: LogLevel, filterCreator?: FilterCreator): ILogItem;
|
||||||
wrapDetached(labelOrValues: LabelOrValues, callback: LogCallback, logLevel: LogLevelOrNull, filterCreator: FilterCreator): void;
|
wrapDetached(labelOrValues: LabelOrValues, callback: LogCallback, logLevel?: LogLevel, filterCreator?: FilterCreator): void;
|
||||||
refDetached(logItem: ILogItem, logLevel: LogLevelOrNull): void;
|
refDetached(logItem: ILogItem, logLevel?: LogLevel): void;
|
||||||
ensureRefId(): void;
|
ensureRefId(): void;
|
||||||
catch(err: Error): Error;
|
catch(err: Error): Error;
|
||||||
finish(): void;
|
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;
|
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 */
|
/** 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);
|
return this._logger.runDetached(labelOrValues, callback, logLevel, filterCreator);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** start a new detached root log item and log a reference to it from this item */
|
/** 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));
|
this.refDetached(this.runDetached(labelOrValues, callback, logLevel, filterCreator));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** logs a reference to a different log item, usually obtained from runDetached.
|
/** logs a reference to a different log item, usually obtained from runDetached.
|
||||||
This is useful if the referenced operation can't be awaited. */
|
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();
|
logItem.ensureRefId();
|
||||||
this.log({ref: (logItem as LogItem)._values.refId}, logLevel);
|
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`.
|
* 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);
|
const item = this.child(labelOrValues, logLevel, filterCreator);
|
||||||
return item.run(callback);
|
return item.run(callback);
|
||||||
}
|
}
|
||||||
@ -160,7 +159,7 @@ export class LogItem implements ILogItem {
|
|||||||
*
|
*
|
||||||
* Hence, the child item is not returned.
|
* 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);
|
const item = this.child(labelOrValues, logLevel);
|
||||||
item.end = item.start;
|
item.end = item.start;
|
||||||
}
|
}
|
||||||
@ -291,7 +290,7 @@ export class LogItem implements ILogItem {
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
child(labelOrValues: LabelOrValues, logLevel: LogLevelOrNull, filterCreator?: FilterCreator): ILogItem {
|
child(labelOrValues: LabelOrValues, logLevel?: LogLevel, filterCreator?: FilterCreator): ILogItem {
|
||||||
if (this.end !== null) {
|
if (this.end !== null) {
|
||||||
console.trace("log item is finished, additional logs will likely not be recorded");
|
console.trace("log item is finished, additional logs will likely not be recorded");
|
||||||
}
|
}
|
||||||
|
@ -101,8 +101,7 @@ async function createStores(db: IDBDatabase, txn: IDBTransaction, oldVersion: nu
|
|||||||
async (log) => {
|
async (log) => {
|
||||||
for (let i = startIdx; i < version; ++i) {
|
for (let i = startIdx; i < version; ++i) {
|
||||||
const migrationFunc = schema[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));
|
||||||
}
|
}
|
||||||
},
|
}) as Promise<void>;
|
||||||
null) as Promise<void>;
|
|
||||||
}
|
}
|
||||||
|
@ -226,7 +226,7 @@ export class Transaction {
|
|||||||
};
|
};
|
||||||
const label = `${this._writeErrors.length} storage write operation(s) failed`;
|
const label = `${this._writeErrors.length} storage write operation(s) failed`;
|
||||||
if (parentItem) {
|
if (parentItem) {
|
||||||
parentItem.wrap(label, callback, null);
|
parentItem.wrap(label, callback);
|
||||||
} else {
|
} else {
|
||||||
this.logger.run(label, callback);
|
this.logger.run(label, callback);
|
||||||
}
|
}
|
||||||
|
@ -196,7 +196,7 @@ async function fixMissingRoomsInUserIdentities(db: IDBDatabase, txn: IDBTransact
|
|||||||
const updatedIdentity = addRoomToIdentity(identity, userId, roomId);
|
const updatedIdentity = addRoomToIdentity(identity, userId, roomId);
|
||||||
if (updatedIdentity) {
|
if (updatedIdentity) {
|
||||||
log.log({l: `fixing up`, id: userId,
|
log.log({l: `fixing up`, id: userId,
|
||||||
roomsBefore: originalRoomCount, roomsAfter: updatedIdentity.roomIds.length}, null);
|
roomsBefore: originalRoomCount, roomsAfter: updatedIdentity.roomIds.length});
|
||||||
userIdentitiesStore.put(updatedIdentity);
|
userIdentitiesStore.put(updatedIdentity);
|
||||||
foundMissing = true;
|
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
|
// so we'll create a new one on the next message that will be properly shared
|
||||||
outboundGroupSessionsStore.delete(roomId);
|
outboundGroupSessionsStore.delete(roomId);
|
||||||
}
|
}
|
||||||
}, null);
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user