diff --git a/apps/server/src/controllers/update-type-logs.controller/listen-to-client.ts b/apps/server/src/controllers/update-type-logs.controller/listen-to-client.ts index c4164ff1..dccb95a8 100644 --- a/apps/server/src/controllers/update-type-logs.controller/listen-to-client.ts +++ b/apps/server/src/controllers/update-type-logs.controller/listen-to-client.ts @@ -57,6 +57,16 @@ export const sendTypeLogController = ({ return; } + store.dispatch.game.sendTypeLog({ + raceId, + playerId, + playerLog: playerLogsToAppPlayerLogs(playerLogs), + }); + + const typeLogsQueue = getTypeLogsQueue(raceId, context); + typeLogsQueue.addLog(playerLogs, playerId); + logger.debug('Type logs are added to race type-logs-queue.', context); + // If all players have completed the race, raise RaceEnd event. const isAllPlayersEnded = checkRaceCompleteInstance.isRaceEnded(); const raceEndData: RaceEndModel = { @@ -73,16 +83,6 @@ export const sendTypeLogController = ({ // Clearing the server timeout when all race players have completed their races from the client side. clearTimeout(serverRaceTimeout); } - - store.dispatch.game.sendTypeLog({ - raceId, - playerId, - playerLog: playerLogsToAppPlayerLogs(playerLogs), - }); - - const typeLogsQueue = getTypeLogsQueue(raceId, context); - typeLogsQueue.addLog(playerLogs, playerId); - logger.debug('Type logs are added to race type-logs-queue.', context); }; pubsub.subscribe(SocketProtocols.SendTypeLog, sendTypeLogController); diff --git a/apps/server/src/services/logger/cloud-logger.ts b/apps/server/src/services/logger/cloud-logger.ts index 740714de..1ea781fd 100644 --- a/apps/server/src/services/logger/cloud-logger.ts +++ b/apps/server/src/services/logger/cloud-logger.ts @@ -12,20 +12,19 @@ const severityMap: Map = new Map([ [LogLevels.Debug, 'DEBUG'], ]); -const logFormat = printf(({ service, context, level, message, ...args }) => { - console.log(`cloudlogger ${service}`, context, message); - - const { subject, ...contextData } = context; - const log = { - service, - subject, - severity: severityMap.get(level), - message, - context: { ...contextData }, - args: Object.keys(args).length ? args : undefined, - }; - return JSON.stringify(log); -}); +const logFormat = printf( + ({ service, subject, context, level, message, ...args }) => { + const log = { + service, + subject, + severity: severityMap.get(level), + message, + context, + args: Object.keys(args).length ? args : undefined, + }; + return JSON.stringify(log); + }, +); export const cloudLogger = (): Logger => { return createLogger({ diff --git a/apps/server/src/services/logger/local-logger.ts b/apps/server/src/services/logger/local-logger.ts index a4b9e940..003cd39e 100644 --- a/apps/server/src/services/logger/local-logger.ts +++ b/apps/server/src/services/logger/local-logger.ts @@ -5,10 +5,9 @@ import { logLevels } from './levels'; const { printf, timestamp, combine, colorize, errors } = format; const logFormat = printf( - ({ service, level, message, timestamp, context, ...args }) => { - const { subject, ...contextData } = context; + ({ service, level, message, timestamp, subject, context, ...args }) => { const additionalData = { - contextData, + context, args: Object.keys(args).length ? args : undefined, }; return `[${service}] (${subject}) ${level}: ${timestamp} - ${message} - ${JSON.stringify( diff --git a/apps/server/src/services/logger/logger.ts b/apps/server/src/services/logger/logger.ts index 65acd7bb..40644c54 100644 --- a/apps/server/src/services/logger/logger.ts +++ b/apps/server/src/services/logger/logger.ts @@ -25,7 +25,6 @@ interface ContextInput { } export interface ContextOutput { - subject: string; // both playerId and socketId won't be available at the same time. playerId?: PlayerId; // socket Id will be available only for initial events. @@ -65,7 +64,6 @@ export class Logger { } return { - subject: this.subject, playerId, socketId, domainId, @@ -78,7 +76,11 @@ export class Logger { context: ContextOutput, additionalData?: T, ): void { - wlogger.error(message, { context, ...additionalData }); + wlogger.error(message, { + subject: this.subject, + context, + ...additionalData, + }); } // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -87,7 +89,11 @@ export class Logger { context: ContextOutput, additionalData?: T, ): void { - wlogger.warn(message, { context, ...additionalData }); + wlogger.warn(message, { + subject: this.subject, + context, + ...additionalData, + }); } // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -96,7 +102,11 @@ export class Logger { context: ContextOutput, additionalData?: T, ): void { - wlogger.info(message, { context, ...additionalData }); + wlogger.info(message, { + subject: this.subject, + context, + ...additionalData, + }); } // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -105,6 +115,10 @@ export class Logger { context: ContextOutput, additionalData?: T, ): void { - wlogger.debug(message, { context, ...additionalData }); + wlogger.debug(message, { + subject: this.subject, + context, + ...additionalData, + }); } }