'Pino-tee logs twice on other logs

References: https://github.com/pinojs/pino-tee

I have two logs, info.log and error.log but the thing is, when I go to info.log, the log for error.log is there

So technically, What I have is :

error.log -> ERROR 1 (W/C correct)

info.log -> ERROR 1, INFO 1 (The error log is there)

What I want is that they go to seperate logs appropriately.

Heres the code from references link above:

const pinoms = require("pino-multi-stream");
const childProcess = require("child_process");
const stream = require("stream");

const cwd = process.cwd();
const { env } = process;

const logThrough = new stream.PassThrough();
const prettyStream = pinoms.prettyStream();
const streams = [{ stream: logThrough }, { stream: prettyStream }];
const log = pinoms(pinoms.multistream(streams));

const child = childProcess.spawn(
  process.execPath,
  [
    require.resolve("pino-tee"),
    "info",
    `${__dirname}/info`,
    "error",
    `${__dirname}/error`,
  ],
  { cwd, env }
);

logThrough.pipe(child.stdin);

module.exports = log;

Logging test on other file:

const logger = require("./Common/logger");
logger.info("INFO 1");
logger.error("ERROR 1");

Result:

info.log

{"level":30,"time":1651894649071,"pid":19380,"hostname":"","msg":"INFO 1"}
{"level":50,"time":1651894649074,"pid":19380,"hostname":"","msg":"ERROR 1"}

error.log

{"level":50,"time":1651894649074,"pid":19380,"hostname":"","msg":"ERROR 1"}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source