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

Question: Is it possible to send to default STDOUT _and_ to another transport? #1741

Closed
muya opened this issue Jul 5, 2023 · 2 comments
Closed

Comments

@muya
Copy link

muya commented Jul 5, 2023

Hello. I'm trying to configure pino as follows:

  • All logs should go out to STDOUT (i.e. the default behaviour)
  • ERROR and above should also be sent to Sentry (via pino-sentry-transport)

However, it seems that enabling pino-sentry-transport disables the STDOUT logging.

How can one configure so that both work?

Note: this is in a production setting (inside a Docker container), so I'd rather not use pino-pretty for STDOUT

I think the approach would be to have some sort of "stdout transport", but I don't know how to configure this together with the pino-sentry-transport.

@muya
Copy link
Author

muya commented Jul 6, 2023

The solution is to use pino/file, with destination set to 1:

Example below is based on Fastify, sending logs to both stdout & Sentry (for error and above)

const transportTargets: TransportTargetOptions[] = [
    {
      target: 'pino/file',
      options: {
        destination: 1
      },
      level: 'info'
    },
    {
      target: 'pino-sentry-transport',
      options: {
        sentry: {
          dsn: 'https://some/sentry/url'
        },
        minLevel: 40
      },
      level: 'info'
    }
  ]

const logger = {
    level: config.logLevel,
    transport: {
      targets: transportTargets
    }
  }

// Pass this logger to the fastify instance

const server: FastifyInstance = Fastify({logger: logger})

// continue with Fastify setup.

@muya muya closed this as completed Jul 6, 2023
@github-actions
Copy link

github-actions bot commented Aug 6, 2023

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant