Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MinimumLevel doesn't seem to do anything #458

Open
VivaLaPanda opened this issue Sep 14, 2023 · 7 comments
Open

MinimumLevel doesn't seem to do anything #458

VivaLaPanda opened this issue Sep 14, 2023 · 7 comments

Comments

@VivaLaPanda
Copy link

I have this command ts-node src/server.ts | yarn pino-pretty -L info -i req.headers,res.headers,dd
But my logs still show this:

2023-09-14 14:08:15.382 web web:dev: [14:08:15.382] DEBUG (58318 on senseofirection.lan):
2023-09-14 14:08:15.382 web web:dev:     query: "SELECT SUM(\"credits\") FROM (SELECT \"public\".\"CreditEntry\".\"credits\" FROM \"public\".\"CreditEntry\" WHERE \"public\".\"CreditEntry\".\"userId\" = $1 OFFSET $2) AS \"sub\""
2023-09-14 14:08:15.382 web web:dev:     duration_ms: 3
2023-09-14 14:08:15.382 web web:dev:     message: "prisma query"
2023-09-14 14:08:15.383 web web:dev: [14:08:15.383] DEBUG (58318 on senseofirection.lan):
2023-09-14 14:08:15.383 web web:dev:     query: "COMMIT"
2023-09-14 14:08:15.383 web web:dev:     duration_ms: 1
2023-09-14 14:08:15.383 web web:dev:     message: "prisma query"
2023-09-14 14:08:15.385 web web:dev: [14:08:15.384] INFO (58318 on senseofirection.lan):
2023-09-14 14:08:15.385 web web:dev:     req: {
2023-09-14 14:08:15.385 web web:dev:       "id": 1,
2023-09-14 14:08:15.385 web web:dev:       "method": "GET",
2023-09-14 14:08:15.385 web web:dev:       "url": "/api/credits/balance",
2023-09-14 14:08:15.385 web web:dev:       "remoteAddress": "::1",
2023-09-14 14:08:15.385 web web:dev:       "remotePort": 61496
2023-09-14 14:08:15.385 web web:dev:     }
2023-09-14 14:08:15.385 web web:dev:     res: {
2023-09-14 14:08:15.385 web web:dev:       "statusCode": 200
2023-09-14 14:08:15.385 web web:dev:     }
2023-09-14 14:08:15.385 web web:dev:     responseTime: 19
2023-09-14 14:08:15.385 web web:dev:     message: "request completed"

I've tried using -L 30 etc, and nothing has worked

@jsumners
Copy link
Member

Possible duplicate #455.

@wdanilo
Copy link

wdanilo commented Jan 9, 2024

I was facing the same issue so I started debugging the implementation. It looks like Pino is filtering messages before they go to transports (which makes sense, but it should be clearly stated in the piano-pretty docs as well). So be sure to also set level on logger, and then it will work fine.

@mcollina
Copy link
Member

Thanks for reporting! Would you like to send a Pull Request to address this issue?

@wdanilo
Copy link

wdanilo commented Jan 12, 2024

@mcollina but there is no error, everything works as expected. Are you talking about a PR to docs to explain it better?

@mcollina
Copy link
Member

yes, exactly!

@nijynot
Copy link

nijynot commented Feb 4, 2024

I have a case where minimumLevel doesn't seem to do anything when using pino.multistream.

const prettyStream = build({
  minimumLevel: "trace",
  colorize: true,
  messageFormat: (log) => {
    let print = "";
    if (Number.isInteger(log?.index)) print += `(${log?.index}) `;
    if (log?.address) print += `${log?.address}: `;
    print += `${log?.msg}`;

    return print;
  },
  ignore: "hostname,address,index",
});
const fileStream = {
  level: "trace",
  stream: fs.createWriteStream(getLogFileName(), { flags: "a" }),
};
const multistream = pino.multistream([fileStream, prettyStream]);

export const logger = pino({ level: "trace" }, multistream);

So level is set in all cases, but still not working for pino-pretty.
It does work for the fileStream, although.

@mcollina
Copy link
Member

mcollina commented Feb 5, 2024

This should work

const prettyStream = build({
  minimumLevel: "trace",
  colorize: true,
  messageFormat: (log) => {
    let print = "";
    if (Number.isInteger(log?.index)) print += `(${log?.index}) `;
    if (log?.address) print += `${log?.address}: `;
    print += `${log?.msg}`;

    return print;
  },
  ignore: "hostname,address,index",
});
const fileStream = {
  level: "trace",
  stream: fs.createWriteStream(getLogFileName(), { flags: "a" }),
};
const multistream = pino.multistream([fileStream, { level: 'trace', stream: prettyStream }]);

export const logger = pino({ level: "trace" }, multistream);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants