Skip to content

Commit

Permalink
rename module property of logger to name
Browse files Browse the repository at this point in the history
  • Loading branch information
drazisil committed Sep 19, 2024
1 parent 468891e commit 2762630
Show file tree
Hide file tree
Showing 30 changed files with 281 additions and 299 deletions.
23 changes: 15 additions & 8 deletions packages/gateway/src/GatewayServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import { ConsoleThread } from "rusty-motors-cli";
import { receiveLobbyData } from "rusty-motors-lobby";
import { receiveLoginData } from "rusty-motors-login";
import { receivePersonaData } from "rusty-motors-personas";

Check warning on line 7 in packages/gateway/src/GatewayServer.ts

View check run for this annotation

Codecov / codecov/patch

packages/gateway/src/GatewayServer.ts#L7

Added line #L7 was not covered by tests
import { Configuration, getServerConfiguration, type ServerLogger } from "rusty-motors-shared";
import {
Configuration,
getServerConfiguration,
type ServerLogger,
} from "rusty-motors-shared";

Check warning on line 12 in packages/gateway/src/GatewayServer.ts

View check run for this annotation

Codecov / codecov/patch

packages/gateway/src/GatewayServer.ts#L12

Added line #L12 was not covered by tests
import {
addOnDataHandler,
createInitialState,
Expand All @@ -15,7 +19,12 @@ import { getServerLogger } from "rusty-motors-shared";
import { receiveTransactionsData } from "rusty-motors-transactions";
import { onSocketConnection } from "./index.js";
import { addWebRoutes } from "./web.js";
import { populateGameMessageProcessors, populatePortToMessageTypes, portToMessageTypes, gameMessageProcessors } from "rusty-motors-nps";
import {
populateGameMessageProcessors,
populatePortToMessageTypes,
portToMessageTypes,
gameMessageProcessors,
} from "rusty-motors-nps";

Check warning on line 27 in packages/gateway/src/GatewayServer.ts

View check run for this annotation

Codecov / codecov/patch

packages/gateway/src/GatewayServer.ts#L27

Added line #L27 was not covered by tests
import { receiveChatData } from "rusty-motors-chat";

/**
Expand Down Expand Up @@ -66,7 +75,7 @@ export class Gateway {
constructor({
config = getServerConfiguration({}),
log = getServerLogger({
module: "GatewayServer",
name: "GatewayServer",

Check warning on line 78 in packages/gateway/src/GatewayServer.ts

View check run for this annotation

Codecov / codecov/patch

packages/gateway/src/GatewayServer.ts#L78

Added line #L78 was not covered by tests
}),
backlogAllowedCount = 0,
listeningPortList = [],
Expand Down Expand Up @@ -241,9 +250,7 @@ export class Gateway {
});
});

this.webServer = fastify({
logger: true,
});
this.webServer = fastify({});

Check warning on line 253 in packages/gateway/src/GatewayServer.ts

View check run for this annotation

Codecov / codecov/patch

packages/gateway/src/GatewayServer.ts#L253

Added line #L253 was not covered by tests
this.webServer.register(FastifySensible);

let state = fetchStateFromDatabase();
Expand Down Expand Up @@ -282,7 +289,7 @@ export class Gateway {
static getInstance({
config = undefined,
log = getServerLogger({
module: "GatewayServer",
name: "GatewayServer",

Check warning on line 292 in packages/gateway/src/GatewayServer.ts

View check run for this annotation

Codecov / codecov/patch

packages/gateway/src/GatewayServer.ts#L292

Added line #L292 was not covered by tests
}),
backlogAllowedCount = 0,
listeningPortList = [],
Expand Down Expand Up @@ -321,7 +328,7 @@ Gateway._instance = undefined;
export function getGatewayServer({
config,
log = getServerLogger({
module: "GatewayServer",
name: "GatewayServer",

Check warning on line 331 in packages/gateway/src/GatewayServer.ts

View check run for this annotation

Codecov / codecov/patch

packages/gateway/src/GatewayServer.ts#L331

Added line #L331 was not covered by tests
}),
backlogAllowedCount = 0,
listeningPortList: listeningPortList = [],
Expand Down
12 changes: 6 additions & 6 deletions packages/gateway/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import * as Sentry from "@sentry/node";
* @property {string} args.connectionId The connection id of the socket that
* received the data.
* @property {module:packages/shared/RawMessage} args.message The data that was received.
* @property {module:shared/log.ServerLogger} [args.log=getServerLogger({ module: "gateway" })] The logger to use.
* @property {module:shared/log.ServerLogger} [args.log=getServerLogger({ name: "gateway" })] The logger to use.
* response
* to the
* data.
Expand All @@ -61,7 +61,7 @@ export function socketErrorHandler({
connectionId,
error,
log = getServerLogger({
module: "socketErrorHandler",
name: "socketErrorHandler",

Check warning on line 64 in packages/gateway/src/index.ts

View check run for this annotation

Codecov / codecov/patch

packages/gateway/src/index.ts#L64

Added line #L64 was not covered by tests
}),
}: {
connectionId: string;
Expand All @@ -81,12 +81,12 @@ export function socketErrorHandler({
*
* @param {object} options
* @param {string} options.connectionId The connection ID
* @param {import("pino").Logger} [options.log=getServerLogger({ module: "socketEndHandler" })] The logger to use
* @param {import("pino").Logger} [options.log=getServerLogger({ name: "socketEndHandler" })] The logger to use
*/
export function socketEndHandler({
connectionId,
log = getServerLogger({
module: "socketEndHandler",
name: "socketEndHandler",

Check warning on line 89 in packages/gateway/src/index.ts

View check run for this annotation

Codecov / codecov/patch

packages/gateway/src/index.ts#L89

Added line #L89 was not covered by tests
}),
}: {
connectionId: string;
Expand All @@ -103,13 +103,13 @@ export function socketEndHandler({
*
* @param {object} options
* @param {Socket} options.incomingSocket The incoming socket
* @param {Logger} [options.log=getServerLogger({ module: "onDataHandler" })] The logger to use
* @param {Logger} [options.log=getServerLogger({ name: "onDataHandler" })] The logger to use
*
*/
export function onSocketConnection({
incomingSocket,
log = getServerLogger({
module: "onDataHandler",
name: "onDataHandler",

Check warning on line 112 in packages/gateway/src/index.ts

View check run for this annotation

Codecov / codecov/patch

packages/gateway/src/index.ts#L112

Added line #L112 was not covered by tests
}),
}: {
incomingSocket: Socket;
Expand Down
3 changes: 1 addition & 2 deletions packages/lobby/src/handlers/_setMyUserData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export async function _setMyUserData({
connectionId,
message,
log = getServerLogger({
module: "Lobby",
name: "Lobby",
level: getServerConfiguration({}).logLevel ?? "info",

Check warning on line 12 in packages/lobby/src/handlers/_setMyUserData.ts

View check run for this annotation

Codecov / codecov/patch

packages/lobby/src/handlers/_setMyUserData.ts#L11-L12

Added lines #L11 - L12 were not covered by tests
}),
}: {
Expand All @@ -25,7 +25,6 @@ export async function _setMyUserData({

log.debug(`User ID: ${incomingMessage._userId}`);


// Update the user's data
updateUser({
userId: incomingMessage._userId,
Expand Down
17 changes: 8 additions & 9 deletions packages/lobby/src/handlers/encryptedCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const messageHandlers: {
* @param {object} args
* @param {string} args.connectionId
* @param {LegacyMessage | MessageBuffer} args.message
* @param {import("pino").Logger} [args.log=getServerLogger({ module: "Lobby" })]
* @param {import("pino").Logger} [args.log=getServerLogger({ name: "Lobby" })]
* @returns {Promise<{
* connectionId: string,
* message: LegacyMessage | MessageBuffer,
Expand All @@ -57,7 +57,7 @@ async function encryptCmd({
connectionId,
message,
log = getServerLogger({
module: "Lobby",
name: "Lobby",

Check warning on line 60 in packages/lobby/src/handlers/encryptedCommand.ts

View check run for this annotation

Codecov / codecov/patch

packages/lobby/src/handlers/encryptedCommand.ts#L60

Added line #L60 was not covered by tests
}),
}: {
connectionId: string;
Expand Down Expand Up @@ -97,7 +97,7 @@ async function encryptCmd({
* @param {object} args
* @param {string} args.connectionId
* @param {LegacyMessage} args.message
* @param {import("pino").Logger} [args.log=getServerLogger({ module: "Lobby" })]
* @param {import("pino").Logger} [args.log=getServerLogger({ name: "Lobby" })]
* @returns {Promise<{
* connectionId: string,
* message: LegacyMessage,
Expand All @@ -107,7 +107,7 @@ async function decryptCmd({
connectionId,
message,
log = getServerLogger({
module: "Lobby",
name: "Lobby",

Check warning on line 110 in packages/lobby/src/handlers/encryptedCommand.ts

View check run for this annotation

Codecov / codecov/patch

packages/lobby/src/handlers/encryptedCommand.ts#L110

Added line #L110 was not covered by tests
}),
}: {
connectionId: string;
Expand Down Expand Up @@ -178,7 +178,7 @@ const npsCommandHandlers: NpsCommandHandler[] = [
* @param {object} args
* @param {string} args.connectionId
* @param {LegacyMessage} args.message
* @param {import("pino").Logger} [args.log=getServerLogger({ module: "Lobby" })]
* @param {import("pino").Logger} [args.log=getServerLogger({ name: "Lobby" })]
* @return {Promise<{
* connectionId: string,
* message: MessageBuffer | LegacyMessage,
Expand All @@ -188,7 +188,7 @@ async function handleCommand({
connectionId,
message,
log = getServerLogger({
module: "Lobby",
name: "Lobby",

Check warning on line 191 in packages/lobby/src/handlers/encryptedCommand.ts

View check run for this annotation

Codecov / codecov/patch

packages/lobby/src/handlers/encryptedCommand.ts#L191

Added line #L191 was not covered by tests
}),
}: {
connectionId: string;
Expand Down Expand Up @@ -228,7 +228,7 @@ async function handleCommand({
* @param {object} args
* @param {string} args.connectionId
* @param {SerializedBufferOld} args.message
* @param {import("pino").Logger} [args.log=getServerLogger({ module: "Lobby" })]
* @param {import("pino").Logger} [args.log=getServerLogger({ name: "Lobby" })]
* @returns {Promise<{
* connectionId: string,
* messages: SerializedBufferOld[],
Expand All @@ -239,7 +239,7 @@ export async function handleEncryptedNPSCommand({
connectionId,
message,
log = getServerLogger({
module: "Lobby",
name: "Lobby",

Check warning on line 242 in packages/lobby/src/handlers/encryptedCommand.ts

View check run for this annotation

Codecov / codecov/patch

packages/lobby/src/handlers/encryptedCommand.ts#L242

Added line #L242 was not covered by tests
}),
}: {
connectionId: string;
Expand All @@ -249,7 +249,6 @@ export async function handleEncryptedNPSCommand({
connectionId: string;
messages: SerializedBufferOld[];
}> {

const inboundMessage = new LegacyMessage();
inboundMessage._doDeserialize(message.data);

Expand Down
4 changes: 2 additions & 2 deletions packages/lobby/src/handlers/handleGetMiniUserList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ user1._userName = "User 1";
* @param {object} args
* @param {string} args.connectionId
* @param {LegacyMessage} args.message
* @param {import("pino").Logger} [args.log=getServerLogger({ module: "Lobby" })]
* @param {import("pino").Logger} [args.log=getServerLogger({ name: "Lobby" })]
*/

export async function handleGetMiniUserList({
connectionId,
message,
log = getServerLogger({
module: "Lobby",
name: "Lobby",
level: getServerConfiguration({}).logLevel ?? "info",

Check warning on line 24 in packages/lobby/src/handlers/handleGetMiniUserList.ts

View check run for this annotation

Codecov / codecov/patch

packages/lobby/src/handlers/handleGetMiniUserList.ts#L23-L24

Added lines #L23 - L24 were not covered by tests
}),
}: {
Expand Down
5 changes: 2 additions & 3 deletions packages/lobby/src/handlers/handleSendMiniRiffList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,20 @@ import { channelRecordSize, channels } from "./channels.js";
* @param {object} args
* @param {string} args.connectionId
* @param {LegacyMessage} args.message
* @param {import("pino").Logger} [args.log=getServerLogger({ module: "Lobby" })]
* @param {import("pino").Logger} [args.log=getServerLogger({ name: "Lobby" })]
*/
export async function handleSendMiniRiffList({
connectionId,
message,
log = getServerLogger({
module: "Lobby",
name: "Lobby",
level: getServerConfiguration({}).logLevel ?? "info",
}),
}: {
connectionId: string;
message: LegacyMessage;
log?: ServerLogger;
}) {

log.debug("Handling NPS_SEND_MINI_RIFF_LIST");
log.debug(`Received command: ${message._doSerialize().toString("hex")}`);

Expand Down
2 changes: 1 addition & 1 deletion packages/lobby/src/handlers/handleTrackingPing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export async function handleTrackingPing({
connectionId,
message,
log = getServerLogger({
module: "Lobby",
name: "Lobby",

Check warning on line 9 in packages/lobby/src/handlers/handleTrackingPing.ts

View check run for this annotation

Codecov / codecov/patch

packages/lobby/src/handlers/handleTrackingPing.ts#L9

Added line #L9 was not covered by tests
}),
}: {
connectionId: string;
Expand Down
9 changes: 3 additions & 6 deletions packages/lobby/src/handlers/heartbeat.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { getServerLogger } from "rusty-motors-shared";
import {
NPSMessage,
SerializedBuffer,
} from "rusty-motors-shared";
import { NPSMessage, SerializedBuffer } from "rusty-motors-shared";

Check warning on line 2 in packages/lobby/src/handlers/heartbeat.js

View check run for this annotation

Codecov / codecov/patch

packages/lobby/src/handlers/heartbeat.js#L2

Added line #L2 was not covered by tests

/**
* @param {object} args
* @param {string} args.connectionId
* @param {SerializedBuffer} args.message
* @param {import("pino").Logger} [args.log=getServerLogger({ module: "Lobby" })]
* @param {import("pino").Logger} [args.log=getServerLogger({ name: "Lobby" })]

Check warning on line 8 in packages/lobby/src/handlers/heartbeat.js

View check run for this annotation

Codecov / codecov/patch

packages/lobby/src/handlers/heartbeat.js#L8

Added line #L8 was not covered by tests
* @returns {Promise<{
* connectionId: string
* messages: SerializedBuffer[],
Expand All @@ -19,7 +16,7 @@ export async function _npsHeartbeat({
// @ts-ignore
message, // eslint-disable-line no-unused-vars
log = getServerLogger({
module: "_npsHeartbeat",
name: "_npsHeartbeat",

Check warning on line 19 in packages/lobby/src/handlers/heartbeat.js

View check run for this annotation

Codecov / codecov/patch

packages/lobby/src/handlers/heartbeat.js#L19

Added line #L19 was not covered by tests
}),
}) {
const packetContent = Buffer.alloc(8);
Expand Down
2 changes: 1 addition & 1 deletion packages/lobby/src/handlers/requestConnectGameServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export async function _npsRequestGameConnectServer({
connectionId,
message,
log = getServerLogger({
module: "LoginServer",
name: "LoginServer",

Check warning on line 49 in packages/lobby/src/handlers/requestConnectGameServer.ts

View check run for this annotation

Codecov / codecov/patch

packages/lobby/src/handlers/requestConnectGameServer.ts#L49

Added line #L49 was not covered by tests
}),
}: ServiceArgs): Promise<{

Check warning on line 51 in packages/lobby/src/handlers/requestConnectGameServer.ts

View check run for this annotation

Codecov / codecov/patch

packages/lobby/src/handlers/requestConnectGameServer.ts#L51

Added line #L51 was not covered by tests
connectionId: string;
Expand Down
17 changes: 5 additions & 12 deletions packages/lobby/src/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const messageHandlers: {
* @param {object} args
* @param {string} args.connectionId
* @param {SerializedBufferOld} args.message
* @param {import("pino").Logger} [args.log=getServerLogger({ module: "PersonaServer" })]
* @param {import("pino").Logger} [args.log=getServerLogger({ name: "PersonaServer" })]
* @returns {Promise<{
* connectionId: string,
* messages: SerializedBufferOld[],
Expand All @@ -83,7 +83,7 @@ export async function receiveLobbyData({
connectionId,
message,
log = getServerLogger({
module: "Lobby",
name: "Lobby",

Check warning on line 86 in packages/lobby/src/internal.ts

View check run for this annotation

Codecov / codecov/patch

packages/lobby/src/internal.ts#L86

Added line #L86 was not covered by tests
}),
}: {
connectionId: string;
Expand All @@ -93,17 +93,14 @@ export async function receiveLobbyData({
connectionId: string;
messages: SerializedBufferOld[];
}> {

/** @type {LegacyMessage | NPSMessage} */
let inboundMessage: LegacyMessage | NPSMessage;

// Check data length
const dataLength = message.getByteSize();

if (dataLength < 4) {
throw Error(
`Data length ${dataLength} is too short to deserialize`,
);
throw Error(`Data length ${dataLength} is too short to deserialize`);

Check warning on line 103 in packages/lobby/src/internal.ts

View check run for this annotation

Codecov / codecov/patch

packages/lobby/src/internal.ts#L103

Added line #L103 was not covered by tests
}

if (dataLength > 12) {
Expand All @@ -128,9 +125,7 @@ export async function receiveLobbyData({

if (typeof supportedHandler === "undefined") {
// We do not yet support this message code
throw Error(
`UNSUPPORTED_MESSAGECODE: ${inboundMessage._header.id}`,
);
throw Error(`UNSUPPORTED_MESSAGECODE: ${inboundMessage._header.id}`);

Check warning on line 128 in packages/lobby/src/internal.ts

View check run for this annotation

Codecov / codecov/patch

packages/lobby/src/internal.ts#L128

Added line #L128 was not covered by tests
}

const buff = new SerializedBufferOld();
Expand All @@ -146,9 +141,7 @@ export async function receiveLobbyData({
log.debug("Leaving receiveLobbyData");
return result;
} catch (error) {
const err = Error(
`Error handling lobby data: ${String(error)}`,
);
const err = Error(`Error handling lobby data: ${String(error)}`);
err.cause = error;
throw err;

Check warning on line 146 in packages/lobby/src/internal.ts

View check run for this annotation

Codecov / codecov/patch

packages/lobby/src/internal.ts#L144-L146

Added lines #L144 - L146 were not covered by tests
}
Expand Down
Loading

0 comments on commit 2762630

Please sign in to comment.