2026-02-17 18:12:02 +07:00
|
|
|
import pino from "pino";
|
|
|
|
|
|
|
|
|
|
export function createLogger(component: string): pino.Logger;
|
2026-08-13 01:57:58 +07:00
|
|
|
export function createLogger(context: Record<string, string | number>): pino.Logger;
|
2026-02-17 18:12:02 +07:00
|
|
|
export function createLogger(
|
2026-08-13 01:57:58 +07:00
|
|
|
componentOrContext: string | Record<string, string | number>
|
2026-02-17 18:12:02 +07:00
|
|
|
): pino.Logger {
|
|
|
|
|
const isString = typeof componentOrContext === "string";
|
2026-08-13 01:57:58 +07:00
|
|
|
const baseContext = isString ? { component: componentOrContext } : componentOrContext;
|
2026-02-17 18:12:02 +07:00
|
|
|
|
|
|
|
|
return pino({
|
|
|
|
|
level: process.env.LOG_LEVEL || "info",
|
|
|
|
|
transport:
|
|
|
|
|
process.env.NODE_ENV !== "production"
|
|
|
|
|
? {
|
|
|
|
|
target: "pino-pretty",
|
|
|
|
|
options: {
|
|
|
|
|
colorize: true,
|
|
|
|
|
translateTime: "HH:MM:ss.l",
|
|
|
|
|
ignore: "pid,hostname",
|
|
|
|
|
singleLine: false,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
: undefined,
|
|
|
|
|
base: baseContext,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const logger = createLogger("shared");
|