Skip to content

Commit c17d6d7

Browse files
committed
Tag each console log in innkeeper
1 parent 26a591a commit c17d6d7

File tree

6 files changed

+21
-19
lines changed

6 files changed

+21
-19
lines changed

innkeeper/src/controllers/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ import { SHOULD_LOG } from '../utils';
33

44
export const sendNotification = (socket: InnkeeperIoSocket | InnkeeperOtherSockets, { type, message }: NotificationMessage) => {
55
const socketData = `${socket.id} (userId: ${socket.data.userId})`;
6-
SHOULD_LOG && console.log(`Sending ${type} notification to ${socketData}: ${message}`);
6+
SHOULD_LOG && console.log(`[OTHER][NOTIF] Sending ${type} notification to ${socketData}: ${message}`);
77
socket.emit('sendNotification', { type, message });
88
};

innkeeper/src/controllers/lobby.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const notifyOnQueue = (io: InnkeeperIoServer, inn: InnState, socket: InnkeeperIo
2323
};
2424

2525
export const handleConnect = (io: InnkeeperIoServer, inn: InnState, socket: InnkeeperIoSocket): void => {
26-
SHOULD_LOG && console.log(`User ${socket.data?.userId} connected to lobby.`);
26+
SHOULD_LOG && console.log(`[LOBBY][Q] User ${socket.data?.userId} connected to lobby.`);
2727
const waitingUsers = inn.getWaitingUsers();
2828
socket.join('lobby');
2929
socket.emit('availableMatches', waitingUsers);
@@ -38,20 +38,20 @@ export const handleMatchingRequest = (
3838
socket.data.lastMessage = getUnixTimestamp();
3939
const { userId, displayName, imageUrl } = socket.data;
4040

41-
SHOULD_LOG && console.log(`User ${displayName} (${userId}) requested a match with parameters ${JSON.stringify(params)}.`);
41+
SHOULD_LOG && console.log(`[LOBBY][Q] User ${displayName} (${userId}) requested a match with parameters ${JSON.stringify(params)}.`);
4242

4343
// Remove user from queue in case this is a re-request.
4444
inn.removeUserFromQueue({ userId, displayName, imageUrl });
4545

4646
const maybeMatch = inn.queueUserOrReturnMatchResult({ userId, displayName, imageUrl }, params);
4747
if (!maybeMatch) {
4848
notifyOnQueue(io, inn, socket);
49-
SHOULD_LOG && console.log(`User ${userId} added to queue.`);
49+
SHOULD_LOG && console.log(`[LOBBY][Q] User ${userId} added to queue.`);
5050
return;
5151
}
5252

5353
const [otherUserId, roomState] = maybeMatch;
54-
SHOULD_LOG && console.log(`Matched users ${userId} and ${otherUserId} in room ${roomState.roomId}.`);
54+
SHOULD_LOG && console.log(`[LOBBY][Q] Matched users ${userId} and ${otherUserId} in room ${roomState.roomId}.`);
5555

5656
io.in('lobby')
5757
.fetchSockets()
@@ -67,12 +67,12 @@ export const handleMatchingRequest = (
6767
otherSocket.data.roomId = roomState.roomId;
6868
otherSocket.emit('sendToRoom', roomState.roomId);
6969
joinAssignedRoom(io, inn, otherSocket);
70-
SHOULD_LOG && console.log(`Sent users ${userId} and ${otherUserId.userId} to room ${roomState.roomId}.`);
70+
SHOULD_LOG && console.log(`[LOBBY][Q] Sent users ${userId} and ${otherUserId.userId} to room ${roomState.roomId}.`);
7171
return;
7272
}
7373

7474
// socket with matching otherUserId could not be found, remove from queue.
75-
console.error(`Could not find socket for userId ${otherUserId} (returned from queue).`);
75+
console.error(`[LOBBY][Q] Could not find socket for userId ${otherUserId} (returned from queue).`);
7676
inn.removeUserFromQueue(otherUserId);
7777

7878
inn.addUserToQueue({ userId, displayName, imageUrl }, params);
@@ -84,5 +84,5 @@ export const handleDisconnect = (io: InnkeeperIoServer, inn: InnState, socket: I
8484
const { userId, displayName, imageUrl } = socket.data;
8585
inn.removeUserFromQueue({ userId, displayName, imageUrl });
8686

87-
SHOULD_LOG && console.log(`User ${userId} disconnected from queue.`);
87+
SHOULD_LOG && console.log(`[LOBBY][Q] User ${userId} disconnected from queue.`);
8888
};

innkeeper/src/controllers/room.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import { getUnixTimestamp } from '../utils';
66
export const getRoomState = (inn: InnState, socket: InnkeeperIoSocket | InnkeeperOtherSockets): RoomState | undefined => {
77
const { roomId } = socket.data;
88
if (!roomId) {
9-
console.error(`Unexpected undefined roomId for socket ${socket.id}. Data: ${socket.data}.`);
9+
console.error(`[ROOM][ERR] Unexpected undefined roomId for socket ${socket.id}. Data: ${socket.data}.`);
1010
return undefined;
1111
}
1212

1313
const roomState = inn.getRoomState(roomId);
1414
if (!roomState) {
15-
console.error(`Unexpected undefined roomState for socket ${socket.id}. Data: ${socket.data}.`);
15+
console.error(`[ROOM][ERR] Unexpected undefined roomState for socket ${socket.id}. Data: ${socket.data}.`);
1616
return undefined;
1717
}
1818

@@ -24,7 +24,7 @@ const getSelfAndOtherUser = (room: RoomState, userId: string): [UserState, UserS
2424
const userState = userStates.find(s => s.userId === userId);
2525
const otherUserState = userStates.find(s => s.userId !== userId);
2626
if (!userState || !otherUserState) {
27-
console.error(`Unexpected user states in ${room.roomId}: ${userStates} (asking for ${userId} & roommate).`);
27+
console.error(`[ROOM][ERR] Unexpected user states in ${room.roomId}: ${userStates} (asking for ${userId} & roommate).`);
2828
return undefined;
2929
}
3030

@@ -195,7 +195,6 @@ export const handleChatMessage = (io: InnkeeperIoServer, inn: InnState, socket:
195195
roomState.chatHistory = [];
196196
}
197197
roomState.chatHistory.push(chatMessage);
198-
console.log(roomState.chatHistory);
199198

200199
// Emit the chat message to all users in the room
201200
io.to(roomState.roomId).emit('sendPartialRoomState', { chatHistory: roomState.chatHistory });

innkeeper/src/index.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,18 @@ const ysocketio = new YS.YSocketIO(io, {
6565
gcEnabled: false,
6666
});
6767

68-
ysocketio.on('document-loaded', (doc: any) => SHOULD_LOG && console.log(`The document ${doc.name} was loaded`));
69-
ysocketio.on('document-update', (doc: any, update: Uint8Array) => SHOULD_LOG && console.log(`The document ${doc.name} is updated`));
68+
ysocketio.on('document-loaded', (doc: any) => SHOULD_LOG && console.log(`[ROOM][YDOC] The document ${doc.name} was loaded`));
69+
ysocketio.on(
70+
'document-update',
71+
(doc: any, update: Uint8Array) => SHOULD_LOG && console.log(`[ROOM][YDOC] The document ${doc.name} is updated`),
72+
);
7073
ysocketio.on('awareness-update', (doc: any, update: Uint8Array) => {
7174
// SHOULD_LOG && console.log(`The awareness of the document ${doc.name} is updated`),
7275
});
73-
ysocketio.on('document-destroy', async (doc: any) => SHOULD_LOG && console.log(`The document ${doc.name} is being destroyed`));
76+
ysocketio.on('document-destroy', async (doc: any) => SHOULD_LOG && console.log(`[ROOM][YDOC] The document ${doc.name} is being destroyed`));
7477
ysocketio.on(
7578
'all-document-connections-closed',
76-
async (doc: any) => SHOULD_LOG && console.log(`All clients of document ${doc.name} are disconnected`),
79+
async (doc: any) => SHOULD_LOG && console.log(`[ROOM][YDOC] All clients of document ${doc.name} are disconnected`),
7780
);
7881

7982
// Execute initialize method

innkeeper/src/models/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,15 @@ export class InnState {
6565
this.matchingParameterToUserMap.forEach((otherUserId, parameters) => {
6666
if (otherUserId.userId === userId.userId) {
6767
this.matchingParameterToUserMap.delete(parameters);
68-
console.log(`Removed user ${userId.userId} from queue.`);
68+
console.log(`[LOBBY][INTERNAL] Removed user ${userId.userId} from queue.`);
6969
}
7070
});
7171
}
7272

7373
addUserToQueue(userId: UserId, parameters: MatchingParameters): void {
7474
this.removeUserFromQueue(userId);
7575
this.matchingParameterToUserMap.set(this.makeConsistentMatchingParameterObject(parameters), userId);
76-
console.log(`Added user ${userId.userId} to queue.`);
76+
console.log(`[LOBBY][INTERNAL] Added user ${userId.userId} to queue.`);
7777
}
7878

7979
getWaitingUsers(): WaitingUsersCount {

innkeeper/src/utils/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export const requireUser = async (
4242
socket.data.roomId = inn.getRoomId(userId);
4343
socket.data.lastMessage = getUnixTimestamp();
4444

45-
SHOULD_LOG && console.log(`User ${userId} connected, with room ${socket.data.roomId}.`);
45+
SHOULD_LOG && console.log(`[OTHER][MIDDLEWARE] User ${userId} connected, with room ${socket.data.roomId}.`);
4646
return next();
4747
};
4848

0 commit comments

Comments
 (0)