mirror of
https://github.com/ZHANGTIANYAO1/teamspeak-music-bot.git
synced 2026-10-02 04:52:50 +08:00
feat: add pino logger with file and stdout transports
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
f152450931
commit
6324953394
1 file changed
+28
@@ -0,0 +1,28 @@
|
||||
import pino from "pino";
|
||||
import { mkdirSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
|
||||
export function createLogger(logDir?: string): pino.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",
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
return pino({ level: "debug" }, transport);
|
||||
}
|
||||
Reference in new issue
Block a user