summaryrefslogtreecommitdiff
path: root/src/lib/pino.ts
blob: a3963614548a8c3c6e373616293c45f4ff5f148d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import pino from "pino";
import type { LokiOptions } from "pino-loki";

let transport;

if (process.env.NODE_ENV === "production") {
  transport = pino.transport<LokiOptions>({
    target: "pino-loki",
    options: {
      host: process.env.LOKI_HOST!,
      basicAuth: {
        username: process.env.LOKI_USERNAME!,
        password: process.env.LOKI_PASSWORD!,
      },
    },
  });
} else {
  transport = pino.transport({
    target: "pino-pretty",
    options: {
      colorize: true,
      translateTime: "SYS:standard",
      ignore: "pid,hostname",
    },
  });
}

/** Application-wide logger instance that writes to Loki in production, pretty-prints locally */
export const logger = pino(transport);