eletrotupi / tcc/ api/src/lib/logger.tsf1edb1555ea0c01ec072ceb15489d8f5fa0df5fb
526 B | 19 lines Raw
1
import pino from "pino";
2

3
// Pretty only on a TTY: in a container stdout is a pipe, so emit plain
4
// single-line JSON that the log collector can parse
5
const pretty = process.env.NODE_ENV !== "production" && process.stdout.isTTY;
6

7
export const logger = pino({
8
  level: process.env.LOG_LEVEL || "info",
9
  ...(pretty && {
10
    transport: {
11
      target: "pino-pretty",
12
      options: {
13
        colorize: true,
14
        singleLine: false,
15
        messageFormat: "{if levelLabel}{levelLabel} - {end}{msg}",
16
      },
17
    },
18
  }),
19
});