mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-06 18:46:49 +00:00
remove slog, use winston instead.
This commit is contained in:
+6
-29
@@ -7,19 +7,18 @@ import { WebSocket, WebSocketServer } from "ws";
|
||||
import { GameEnv } from "../core/configuration/Config";
|
||||
import { getServerConfigFromServer } from "../core/configuration/ConfigLoader";
|
||||
import { GameType } from "../core/game/Game";
|
||||
import { GameConfig, GameRecord, LogSeverity } from "../core/Schemas";
|
||||
import { GameConfig, GameRecord } from "../core/Schemas";
|
||||
import { archive, readGameRecord } from "./Archive";
|
||||
import { Client } from "./Client";
|
||||
import { GameManager } from "./GameManager";
|
||||
import { gatekeeper, LimiterType } from "./Gatekeeper";
|
||||
import { logger } from "./Logger";
|
||||
import { slog } from "./StructuredLog";
|
||||
import { metrics } from "./WorkerMetrics";
|
||||
|
||||
const config = getServerConfigFromServer();
|
||||
|
||||
const workerId = parseInt(process.env.WORKER_ID || "0");
|
||||
const log = logger.child({ component: `worker_${workerId}` });
|
||||
const log = logger.child({ comp: `w_${workerId}` });
|
||||
|
||||
// Worker setup
|
||||
export function startWorker() {
|
||||
@@ -340,7 +339,7 @@ export function startWorker() {
|
||||
// The load balancer will handle routing to this server based on path
|
||||
const PORT = config.workerPortByIndex(workerId);
|
||||
server.listen(PORT, () => {
|
||||
log.info(`Worker ${workerId} running on http://localhost:${PORT}`);
|
||||
log.info(`running on http://localhost:${PORT}`);
|
||||
log.info(`Handling requests with path prefix /w${workerId}/`);
|
||||
// Signal to the master process that this worker is ready
|
||||
if (process.send) {
|
||||
@@ -348,44 +347,22 @@ export function startWorker() {
|
||||
type: "WORKER_READY",
|
||||
workerId: workerId,
|
||||
});
|
||||
log.info(`Worker ${workerId} signaled ready state to master`);
|
||||
log.info(`signaled ready state to master`);
|
||||
}
|
||||
});
|
||||
|
||||
// Global error handler
|
||||
app.use((err: Error, req: Request, res: Response, next: NextFunction) => {
|
||||
log.error(`Error in ${req.method} ${req.path}:`, err);
|
||||
slog({
|
||||
logKey: "server_error",
|
||||
msg: `Unhandled exception in ${req.method} ${req.path}: ${err.message}`,
|
||||
severity: LogSeverity.Error,
|
||||
stack: err.stack,
|
||||
});
|
||||
res.status(500).json({ error: "An unexpected error occurred" });
|
||||
});
|
||||
|
||||
// Process-level error handlers
|
||||
process.on("uncaughtException", (err) => {
|
||||
log.error(`Worker ${workerId} uncaught exception:`, err);
|
||||
slog({
|
||||
logKey: "uncaught_exception",
|
||||
msg: `Worker ${workerId} uncaught exception: ${err.message}`,
|
||||
severity: LogSeverity.Error,
|
||||
stack: err.stack,
|
||||
});
|
||||
log.error(`uncaught exception:`, err);
|
||||
});
|
||||
|
||||
process.on("unhandledRejection", (reason, promise) => {
|
||||
log.error(
|
||||
`Worker ${workerId} unhandled rejection at:`,
|
||||
promise,
|
||||
"reason:",
|
||||
reason,
|
||||
);
|
||||
slog({
|
||||
logKey: "unhandled_rejection",
|
||||
msg: `Worker ${workerId} unhandled promise rejection: ${reason}`,
|
||||
severity: LogSeverity.Error,
|
||||
});
|
||||
log.error(`unhandled rejection at:`, promise, "reason:", reason);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user