1
9import pino, { type Logger } from "pino";
10
11const isDev =
12 (typeof process.env.NODE_ENV === "undefined" ? "development" : process.env.NODE_ENV) !==
13 "production";
14
15const base = pino({
16 level: process.env.LOG_LEVEL ?? (isDev ? "debug" : "info"),
17 base: { svc: "factory-worker" },
18 timestamp: pino.stdTimeFunctions.isoTime,
19 ...(isDev
20 ? {
21 transport: {
22 target: "pino-pretty",
23 options: {
24 colorize: true,
25 translateTime: "SYS:HH:MM:ss",
26 ignore: "pid,hostname,svc"
27 }
28 }
29 }
30 : {})
31});
32
33const children = new Map<string, Logger>();
34
35
36export function getLogger(module: string): Logger {
37 let child = children.get(module);
38 if (!child) {
39 child = base.child({ mod: module });
40 children.set(module, child);
41 }
42 return child;
43}
44
45export type { Logger };
46