2026-06-01 21:44:29 +07:00
|
|
|
import pino from "pino";
|
|
|
|
|
|
2026-06-02 21:06:42 +07:00
|
|
|
const rootLogger = pino({
|
|
|
|
|
level: process.env.LOG_LEVEL || "info",
|
|
|
|
|
transport:
|
|
|
|
|
process.env.NODE_ENV === "development"
|
|
|
|
|
? {
|
|
|
|
|
target: "pino-pretty",
|
|
|
|
|
options: {
|
|
|
|
|
colorize: true,
|
|
|
|
|
translateTime: "SYS:standard",
|
|
|
|
|
ignore: "pid,hostname",
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
: undefined,
|
|
|
|
|
} as pino.LoggerOptions);
|
2026-06-01 21:44:29 +07:00
|
|
|
|
2026-06-02 21:06:42 +07:00
|
|
|
export type Logger = ReturnType<typeof createChildLogger>;
|
2026-06-01 21:44:29 +07:00
|
|
|
|
2026-06-02 21:23:12 +07:00
|
|
|
/**
|
|
|
|
|
* Alias for backwards compatibility (discord-gateway uses this name).
|
|
|
|
|
*/
|
|
|
|
|
export type CustomLogger = Logger;
|
|
|
|
|
|
2026-06-02 21:06:42 +07:00
|
|
|
/**
|
|
|
|
|
* Returns a child logger bound to the root singleton via pino's .child().
|
|
|
|
|
* Preserves parent context and is efficient (no transport re-init per call).
|
|
|
|
|
*/
|
2026-06-01 21:44:29 +07:00
|
|
|
export function createChildLogger(context: string) {
|
2026-06-02 21:06:42 +07:00
|
|
|
return rootLogger.child({ context });
|
|
|
|
|
}
|