2023-02-13 12:41:30 +00:00
|
|
|
import pino, { LoggerOptions } from "pino";
|
2023-06-02 14:05:20 +00:00
|
|
|
import { IMetamigoConfig } from "./config/index.js";
|
2023-02-13 12:41:30 +00:00
|
|
|
|
2023-03-13 11:46:12 +00:00
|
|
|
export const getPrettyPrint = <T extends IMetamigoConfig>(
|
|
|
|
|
config: T
|
|
|
|
|
): boolean => {
|
2023-02-13 12:41:30 +00:00
|
|
|
const { prettyPrint } = config.logging;
|
|
|
|
|
if (prettyPrint === "auto") return config?.isDev || false;
|
|
|
|
|
return prettyPrint === true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const configureLogger = <T extends IMetamigoConfig>(
|
|
|
|
|
config: T
|
|
|
|
|
): pino.Logger => {
|
|
|
|
|
const { level, redact } = config.logging;
|
|
|
|
|
const options: LoggerOptions = {
|
|
|
|
|
level,
|
|
|
|
|
redact: {
|
|
|
|
|
paths: redact,
|
|
|
|
|
remove: true,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
return pino(options);
|
|
|
|
|
};
|