pinojs / pino-pretty

🌲Basic prettifier for Pino log lines
MIT License
1.27k stars 150 forks source link

pino-pretty not work under docker/PM2 #303

Closed jaclas closed 2 years ago

jaclas commented 2 years ago

The code contains two ways to use pino, with pino-pretty and with the old flag prettyPrint = true (for comparison).

import pino from "pino";

const initA = {
    transport: {
        target: "pino-pretty",
        options: {
            colorize: true,
            translateTime : "yyyy-mm-dd HH:MM:ss.l",
            ignore: "pid,hostname",
            destination: 1
        }
    },
    level: "trace"
};

const initB = {
    level: "trace",
    prettyPrint: true
};

export function getLogger(init) { 
    const logger = pino(init);
    console.info("console: logger created!");
    return logger; 
}

export function test() {
    console.log("************************");
    console.log("runtime:");
    console.log(process.versions);
    let logger = getLogger(initA);
    logger.info("logger A (pino-pretty) created!");
    logger.warn("logger A (pino-pretty) created!");
    logger.error("logger A (pino-pretty) created!");
    logger.debug("logger A (pino-pretty) created!");
    logger.fatal("logger A (pino-pretty) created!");

    logger = getLogger(initB);
    logger.info("logger B (prettyPrint) created!");
    logger.warn("logger B (prettyPrint) created!");
    logger.error("logger B (prettyPrint) created!");
    logger.debug("logger B (prettyPrint) created!");
    logger.fatal("logger B (prettyPrint) created!");
    console.log("************************");
}

test();

When I run this code on the development machine it works ok, it looks like this:

image

However, when I run it in a test environment, on a docker and from under PM2 then pino-pretty stops working: image

What is the cause and how to fix it?

I am using the latest version of pino and pino-prettty.

jsumners commented 2 years ago

Would you like to send a Pull Request to address this issue? Remember to add unit tests.

jaclas commented 2 years ago

Sorry, I don't know how to do this, I'm a beginner :-(

jsumners commented 2 years ago

Unfortunately, I will have to close this as unsupported. PM2 modifies core objects.