From 72c6172a4550710f750790d5ca9c900adeb0384a Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Wed, 3 May 2023 00:01:59 +0530 Subject: [PATCH] Implement a method to discard logs --- src/logging/LogItem.ts | 11 +++++++++++ src/logging/types.ts | 1 + src/matrix/calls/group/GroupCall.ts | 5 +++++ 3 files changed, 17 insertions(+) diff --git a/src/logging/LogItem.ts b/src/logging/LogItem.ts index 5aaabcc4..91ad4e8f 100644 --- a/src/logging/LogItem.ts +++ b/src/logging/LogItem.ts @@ -28,6 +28,7 @@ export class LogItem implements ILogItem { protected _logger: Logger; private _filterCreator?: FilterCreator; private _children?: Array; + private _discard: boolean = false; constructor(labelOrValues: LabelOrValues, logLevel: LogLevel, logger: Logger, filterCreator?: FilterCreator) { this._logger = logger; @@ -38,6 +39,13 @@ export class LogItem implements ILogItem { this._filterCreator = filterCreator; } + /** + * Prevents this log item from being present in the exported output. + */ + discard(): void { + this._discard = true; + } + /** start a new root log item and run it detached mode, see Logger.runDetached */ runDetached(labelOrValues: LabelOrValues, callback: LogCallback, logLevel?: LogLevel, filterCreator?: FilterCreator): ILogItem { return this._logger.runDetached(labelOrValues, callback, logLevel, filterCreator); @@ -119,6 +127,9 @@ export class LogItem implements ILogItem { } serialize(filter: LogFilter, parentStartTime: number | undefined, forced: boolean): ISerializedItem | undefined { + if (this._discard) { + return; + } if (this._filterCreator) { try { filter = this._filterCreator(new LogFilter(filter), this); diff --git a/src/logging/types.ts b/src/logging/types.ts index 54436423..7e81d929 100644 --- a/src/logging/types.ts +++ b/src/logging/types.ts @@ -55,6 +55,7 @@ export interface ILogItem { finish(): void; forceFinish(): void; child(labelOrValues: LabelOrValues, logLevel?: LogLevel, filterCreator?: FilterCreator): ILogItem; + discard(): void; } /* extend both ILogger and ILogItem from this interface, but need to rename ILogger.run => wrap then. Or both to `span`? diff --git a/src/matrix/calls/group/GroupCall.ts b/src/matrix/calls/group/GroupCall.ts index a47a3ff2..2a580c5c 100644 --- a/src/matrix/calls/group/GroupCall.ts +++ b/src/matrix/calls/group/GroupCall.ts @@ -424,6 +424,11 @@ export class GroupCall extends EventEmitter<{change: never}> { member.dispose(); this._members.remove(memberKey); log.set("removed", true); + } else { + // We don't want to pollute the logs with all the expired members. + // This can be an issue for long lived calls that have had a large number + // of users join and leave at some point in time. + log.discard(); } return; }