Skip to content

Commit

Permalink
refactor: include room id in room status logs
Browse files Browse the repository at this point in the history
Makes it easier to debug
  • Loading branch information
AndyTWF committed Nov 8, 2024
1 parent 8f9f166 commit 513a8ec
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 54 deletions.
6 changes: 4 additions & 2 deletions src/core/room-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,15 @@ export class DefaultRoomLifecycle extends EventEmitter<RoomStatusEventsMap> impl
private _error?: Ably.ErrorInfo;
private readonly _logger: Logger;
private readonly _internalEmitter = new EventEmitter<RoomStatusEventsMap>();
private readonly _roomId: string;

/**
* Constructs a new `DefaultStatus` instance.
* @param logger The logger to use.
*/
constructor(logger: Logger) {
constructor(roomId: string, logger: Logger) {
super();
this._roomId = roomId;
this._logger = logger;
this._status = RoomStatus.Initialized;
this._error = undefined;
Expand Down Expand Up @@ -231,7 +233,7 @@ export class DefaultRoomLifecycle extends EventEmitter<RoomStatusEventsMap> impl

this._status = change.current;
this._error = change.error;
this._logger.info(`Room status changed`, change);
this._logger.info(`room status changed`, { ...change, roomId: this._roomId });
this._internalEmitter.emit(change.current, change);
this.emit(change.current, change);
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export class DefaultRoom implements Room {
this._options = options;
this._chatApi = chatApi;
this._logger = logger;
this._lifecycle = new DefaultRoomLifecycle(logger);
this._lifecycle = new DefaultRoomLifecycle(roomId, logger);

// Setup features
this._messages = new DefaultMessages(roomId, realtime, this._chatApi, realtime.auth.clientId, logger);
Expand Down
Loading

0 comments on commit 513a8ec

Please sign in to comment.