I create a logger with pino(prettyLogger) and I have a problem when I try print the to console with:
“prettyLogger.debug”. It prints nothing.
But if I use “prettyLogger.info” it’s working.
What am I doing wrong?
const logLevel = "trace";
const { prettyLogger } = createLogger(logLevel);
prettyLogger.debug("dont work");
prettyLogger.info("work");
// logger
import pino from "pino";
import path from "path";
import fs from "fs";
import publicPath from "../config/publicPath";
// Function to get the current date in YYYY-MM-DD format
const getFormattedDate = () => {
const now = new Date();
const year = now.getFullYear();
const month = String(now.getMonth() + 1).padStart(2, "0"); // Months are zero-based
const day = String(now.getDate()).padStart(2, "0");
return `${year}-${month}-${day}`;
};
// Function to create a pino logger with a specific level
export function createLogger(level: string) {
// For file logging
const logFilePath = path.join(
publicPath,
"../logs",
`pino-app-error-${getFormattedDate()}.log`
);
// Ensure the directory exists
fs.mkdirSync(path.dirname(logFilePath), { recursive: true });
const transport = pino.transport({
targets: [
{
level,
target: "pino-pretty",
options: {
colorize: true,
translateTime: "SYS:standard",
},
},
{
level,
target: "pino/file",
options: { destination: logFilePath },
},
],
});
const prettyLogger = pino(transport);
return { prettyLogger };
}