Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix large log files generated when calls are used #1080

Merged
merged 3 commits into from
May 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/logging/LogItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class LogItem implements ILogItem {
protected _logger: Logger;
private _filterCreator?: FilterCreator;
private _children?: Array<LogItem>;
private _discard: boolean = false;

constructor(labelOrValues: LabelOrValues, logLevel: LogLevel, logger: Logger, filterCreator?: FilterCreator) {
this._logger = logger;
Expand All @@ -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<unknown>, logLevel?: LogLevel, filterCreator?: FilterCreator): ILogItem {
return this._logger.runDetached(labelOrValues, callback, logLevel, filterCreator);
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/logging/NullLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ export class NullLogItem implements ILogItem {
this.logger = logger;
}

discard(): void {
// noop
}

wrap<T>(_: LabelOrValues, callback: LogCallback<T>): T {
return this.run(callback);
}
Expand Down
1 change: 1 addition & 0 deletions src/logging/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`?
Expand Down
7 changes: 3 additions & 4 deletions src/matrix/Session.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ export class Session {
this._roomsBeingCreated = new ObservableMap();
this._user = new User(sessionInfo.userId);
this._roomStateHandler = new RoomStateHandlerSet();
if (features.calls) {
this._setupCallHandler();
}
this._deviceMessageHandler = new DeviceMessageHandler({storage, callHandler: this._callHandler});
this._olm = olm;
this._olmUtil = null;
Expand Down Expand Up @@ -106,10 +109,6 @@ export class Session {
this._createRoomEncryption = this._createRoomEncryption.bind(this);
this._forgetArchivedRoom = this._forgetArchivedRoom.bind(this);
this.needsKeyBackup = new ObservableValue(false);

if (features.calls) {
this._setupCallHandler();
}
}

get fingerprintKey() {
Expand Down
5 changes: 5 additions & 0 deletions src/matrix/calls/group/GroupCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down