Files
teamspeak-music-bot/src/logger.ts
T
Claude 168f9f0286 Fix EINTR crash from pino ThreadStream during FFmpeg playback
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
2026-03-31 16:52:53 +00:00

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);
}