Implement a method to discard logs

This commit is contained in:
RMidhunSuresh 2023-05-03 00:01:59 +05:30
parent 99e67fedc3
commit 72c6172a45
3 changed files with 17 additions and 0 deletions

View File

@ -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;
@ -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);
@ -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);

View File

@ -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`?

View File

@ -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;
}