2023-03-16 10:17:00 +00:00
|
|
|
import pino from "pino";
|
|
|
|
|
2023-06-01 14:33:25 +00:00
|
|
|
const forbiddenProductionLevels = ["debug", "trace"];
|
|
|
|
|
|
|
|
const logLevel = process.env.APP_LOG_LEVEL ?? "silent";
|
|
|
|
|
|
|
|
if (process.env.NODE_ENV === "production" && forbiddenProductionLevels.includes(logLevel)) {
|
|
|
|
throw new Error(
|
|
|
|
`Production app can only log INFO or higher log level. "${logLevel}" is development only.`
|
|
|
|
);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
2023-03-16 10:17:00 +00:00
|
|
|
/**
|
|
|
|
* TODO Set up log drain etc
|
|
|
|
*/
|
|
|
|
export const logger = pino({
|
2023-06-01 14:33:25 +00:00
|
|
|
level: logLevel,
|
2023-05-05 06:15:47 +00:00
|
|
|
redact: ["token", "apiKey"],
|
2023-03-16 10:17:00 +00:00
|
|
|
transport:
|
|
|
|
process.env.NODE_ENV === "development"
|
|
|
|
? {
|
|
|
|
target: "pino-pretty",
|
|
|
|
options: {
|
|
|
|
colorize: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
: undefined,
|
|
|
|
});
|
|
|
|
|
|
|
|
export const createLogger = logger.child.bind(logger);
|
2023-05-05 06:15:47 +00:00
|
|
|
|
|
|
|
export type Logger = typeof logger;
|