mirror of
https://github.com/ZHANGTIANYAO1/teamspeak-music-bot.git
synced 2026-10-01 20:42:50 +08:00
The pino logger's ThreadStream was throwing unhandled EINTR errors when FFmpeg child processes were spawned, crashing the entire bot. Add an error handler to suppress EINTR and prevent process crashes. https://claude.ai/code/session_01EjpEsC2GCsvwbu4n3XC8EE
37 lines
920 B
TypeScript
37 lines
920 B
TypeScript
import pino from "pino";
|
|
import { mkdirSync } from "node:fs";
|
|
import { join } from "node:path";
|
|
|
|
export type Logger = pino.Logger;
|
|
|
|
export function createLogger(logDir?: string): Logger {
|
|
if (!logDir) {
|
|
return pino({ level: "info" });
|
|
}
|
|
|
|
mkdirSync(logDir, { recursive: true });
|
|
|
|
const transport = pino.transport({
|
|
targets: [
|
|
{
|
|
target: "pino/file",
|
|
options: { destination: 1 }, // stdout
|
|
level: "info",
|
|
},
|
|
{
|
|
target: "pino/file",
|
|
options: { destination: join(logDir, "bot.log"), mkdir: true },
|
|
level: "debug",
|
|
},
|
|
],
|
|
});
|
|
|
|
// Prevent EINTR errors from crashing the process (known pino/thread-stream issue on Linux)
|
|
transport.on("error", (err: Error) => {
|
|
if ((err as NodeJS.ErrnoException).code === "EINTR") return;
|
|
console.error("Logger transport error:", err);
|
|
});
|
|
|
|
return pino({ level: "debug" }, transport);
|
|
}
|