Skip to content

Commit

Permalink
Merge pull request #115 from the-ai-team/fix/114-fix-minor-errors
Browse files Browse the repository at this point in the history
[Related #112] Fix minor errors
  • Loading branch information
supunTE authored Mar 18, 2024
2 parents 231a282 + 76c8531 commit e24beea
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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);
27 changes: 13 additions & 14 deletions apps/server/src/services/logger/cloud-logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,19 @@ const severityMap: Map<string, string> = 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({
Expand Down
5 changes: 2 additions & 3 deletions apps/server/src/services/logger/local-logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
26 changes: 20 additions & 6 deletions apps/server/src/services/logger/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -65,7 +64,6 @@ export class Logger {
}

return {
subject: this.subject,
playerId,
socketId,
domainId,
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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,
});
}
}

0 comments on commit e24beea

Please sign in to comment.