diff --git a/server/src/functions/logger.ts b/server/src/functions/logger.ts index ec43c7f..e72c846 100644 --- a/server/src/functions/logger.ts +++ b/server/src/functions/logger.ts @@ -1,22 +1,18 @@ -import { createLogger as createWinstonLogger, format, transports, Logger } from "winston"; +import { createLogger as createWinstonLogger, format, transports, Logger as WinstonLogger } from "winston"; import colors from "colors"; /** * Creates a logger with colored output for console. - * - * @param {string | number} [context="Socket"] - The context identifier for the logger. - * @returns {Logger} - A configured Winston logger instance. */ -export function Logger(context: string): Logger { - return createWinstonLogger({ +const logger = createWinstonLogger({ level: "info", format: format.combine( format.timestamp({ format: "YYYY-MM-DD HH:mm:ss", // Example: 2025-01-15 14:30:45 }), format.printf((info) => { - const timestamp = colors.green(info.timestamp); // Green for timestamp - const prefix = `[${colors.cyan(context)}]`; // Cyan for context + const timestamp = colors.green(info.timestamp as string); // Green for timestamp + const prefix = `[${colors.cyan('server')}]`; // Cyan for context const level = { error: colors.red(info.level.toUpperCase()), // Red for errors warn: colors.yellow(info.level.toUpperCase()), // Yellow for warnings @@ -37,4 +33,5 @@ export function Logger(context: string): Logger { new transports.Console(), ], }); -} + +export { logger }; \ No newline at end of file diff --git a/server/src/main.ts b/server/src/main.ts index 4810f99..b02e456 100644 --- a/server/src/main.ts +++ b/server/src/main.ts @@ -1,4 +1,4 @@ -import { Logger } from "./functions/logger"; +import { logger } from "./functions/logger"; import express from "express"; import { createServer } from "node:http"; import { Server, type Socket } from "socket.io"; @@ -12,7 +12,6 @@ import type { } from "./types/rooms"; import colors from "colors"; import "dotenv/config" -const logger = Logger("Server"); /** * Initializes the Express application. @@ -123,7 +122,7 @@ io.on("connection", (socket: Socket) => { io.to(room_code).emit("update_room", { room_player, room }); - logger.info(`Player "${colors.bold.brightGreen.underline(room_player)}" joined room "${colors.bold.brightGreen.underline(room_code)}".`); + logger.info(`Player "${colors.bold.green.underline(room_player)}" joined room "${colors.bold.green.underline(room_code)}".`); }); /** @@ -197,7 +196,7 @@ io.on("connection", (socket: Socket) => { io.to(randomRoom.code).emit("update_room", { room_player, room: randomRoom }); - logger.info(`Player "${colors.bold.brightGreen.underline(room_player)}" joined random room "${randomRoom.code}".`); + logger.info(`Player "${colors.bold.green.underline(room_player)}" joined random room "${randomRoom.code}".`); }); /** @@ -317,5 +316,5 @@ io.on("connection", (socket: Socket) => { HTTP.listen(process.env.PORT, () => { - logger.info(`Socket running: ` + colors.bold.brightGreen.underline(`http://0.0.0.0:${process.env.PORT}`)); + logger.info(`Socket running: ` + colors.bold.green.underline(`http://0.0.0.0:${process.env.PORT}`)); });