File size: 1,425 Bytes
fb38ec5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { FastifyServerOptions } from "fastify";
import { env } from "./env.js";
import stringify from "json-stringify-safe";

interface LoggingConfig {
  [key: string]: FastifyServerOptions["logger"];
}

export const loggingConfig: LoggingConfig = {
  development: {
    transport: {
      target: "pino-pretty",
      options: {
        translateTime: "HH:MM:ss Z",
        ignore: "pid,hostname",
      },
    },
    ...(env.ENABLE_VERBOSE_LOGGING
      ? {
          hooks: {
            logMethod(inputArgs: any[], method: any) {
              if (inputArgs.length > 1) {
                try {
                  let resultingMessage = "";
                  if (typeof inputArgs[0] === "string") {
                    const [message, ...args] = inputArgs;
                    resultingMessage = `${message} ${stringify(args)}`;
                  } else {
                    resultingMessage = stringify(inputArgs);
                  }
                  return method.apply(this, [resultingMessage]);
                } catch (error) {
                  console.error(
                    "Error trying to process logs with verbose logging enabled: ",
                    error,
                  );
                }
              }
              return method.apply(this, inputArgs);
            },
          },
        }
      : {}),
    level: process.env.LOG_LEVEL || "debug",
  },
  production: {},
  test: false,
};