Closed SGudbrandsson closed 9 months ago
I think this should work:
import pino from "pino";
import pretty from "pino-pretty";
import { createWriteStream } from "pino-sentry";
const stream = createWriteStream({
dsn: process.env.SENTRY_DSN,
environment: process.env.NODE_ENV || "development",
level: "error",
});
const streams = [stream];
if (process.env.NODE_ENV !== "production") {
const pp = pretty({
colorize: true,
ignore: "pid,hostname",
minimumLevel: "debug",
});
streams.push({ level: 'debug', stream: pp });
}
export const logger = pino({ level: "debug" }, pino.multistream(streams));
console.log(logger.isLevelEnabled("debug"));
logger.debug("Logger initialized");
console.log("Logger finished");
I know this is verbose, a PR to improve things would be highly welcomed.
This worked, thanks!!!
I'll see what I can do with a PR real quick. The biggest win would be a documentation update, so I'll add that at least. Since the initialization flow is the way it is, the only thing I can think of is to have some config builder that would prepare a standard object for initializing streams, transports, etc.
I don't have a clear idea of how to execute that cleanly without a sizeable refactor. I'll add the documenation bit in a PR though.
No, looks like this is documented here https://github.com/pinojs/pino/blob/89fc326c7a118032ad1c0df355f72e49e90c5bed/docs/help.md#log-to-different-streams
I just didn't see it
I'll see if I can make a PR that simplifies this a bit later.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
I'm attempting to use multiple streams in pino, however, I'm unable to get debug messages to be printed in stdout.
Here's an example code, along with the accompanying screenshot
If I remove streams and use only the
pino({ level: "debug" });
then I get debug logs.Do you have any idea what might be wrong?