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

Helper to help components spit out debug logs #2349

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 7 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,7 @@ export enum ClientEvent {
DeleteRoom = "deleteRoom",
SyncUnexpectedError = "sync.unexpectedError",
ClientWellKnown = "WellKnown.client",
DumpDebugLogs = "logging.dumpDebugLogs",
}

type RoomEvents = RoomEvent.Name
Expand Down Expand Up @@ -852,6 +853,7 @@ export type ClientEventHandlerMap = {
[ClientEvent.DeleteRoom]: (roomId: string) => void;
[ClientEvent.SyncUnexpectedError]: (error: Error) => void;
[ClientEvent.ClientWellKnown]: (data: IClientWellKnown) => void;
[ClientEvent.DumpDebugLogs]: () => void;
} & RoomEventHandlerMap
& RoomStateEventHandlerMap
& CryptoEventHandlerMap
Expand Down Expand Up @@ -8963,6 +8965,11 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
},
);
}

public dumpDebugLogs() {
logger.debug('matrix-js-sdk: dumping extra debug logs to the console');
this.emit(ClientEvent.DumpDebugLogs);
}
Comment on lines +8967 to +8970
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using logs is a really bad mechanism given that it relies on consumers monkey-patching console which we don't say anywhere in the generated docs to do

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't have to live in matrix-js-sdk. What event emitter pattern can we use exclusively in matrix-react-sdk? This point is tracked by matrix-org/matrix-react-sdk#8502 (comment)

}

/**
Expand Down
7 changes: 7 additions & 0 deletions src/models/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,13 @@ export class Room extends TypedEventEmitter<EmittedEvents, RoomEventHandlerMap>
return Array.from(this.threads.values());
}

/**
* @experimental
*/
public getThreadsMap(): Map<string, Thread> {
return this.threads;
}
MadLittleMods marked this conversation as resolved.
Show resolved Hide resolved

/**
* Get a member from the current room state.
* @param {string} userId The user ID of the member.
Expand Down
18 changes: 17 additions & 1 deletion src/timeline-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ limitations under the License.

import { Direction, EventTimeline } from './models/event-timeline';
import { logger } from './logger';
import { MatrixClient } from "./client";
import { MatrixClient, ClientEvent } from "./client";
import { EventTimelineSet } from "./models/event-timeline-set";
import { MatrixEvent } from "./models/event";

Expand All @@ -41,10 +41,14 @@ const DEFAULT_PAGINATE_LOOP_LIMIT = 5;

interface IOpts {
windowLimit?: number;
// A label used in the logs to namespace and differentiate the timelines.
//ex. main timeline from the thread timeline.
contextLabel?: string;
MadLittleMods marked this conversation as resolved.
Show resolved Hide resolved
}

export class TimelineWindow {
private readonly windowLimit: number;
private readonly contextLabel: string;
// these will be TimelineIndex objects; they delineate the 'start' and
// 'end' of the window.
//
Expand Down Expand Up @@ -80,14 +84,26 @@ export class TimelineWindow {
* in the window. If more events are retrieved via pagination requests,
* excess events will be dropped from the other end of the window.
*
* @param {number} [opts.contextLabel] A label used in the logs to namespace
* and differentiate the timelines. ex. main timeline from the thread timeline.
*
* @constructor
*/
constructor(
private readonly client: MatrixClient,
private readonly timelineSet: EventTimelineSet,
opts: IOpts = {},
) {
console.log('timeline-window', opts);
this.windowLimit = opts.windowLimit || 1000;
this.contextLabel = opts.contextLabel || '';

// TODO: Unbind this when the object is destroyed
client.on(ClientEvent.DumpDebugLogs, this.onDumpDebugLogs);
}

private onDumpDebugLogs = (): void => {
logger.debug(`timeline-window(${this.contextLabel}): TODO: dumpDebugLogs`);
}

/**
Expand Down