Logging to multiple transports

Is it possible to log to multiple transports?

I want to log to console, but also to winston-sentry for errors.

1 Like

Yes you can switch transports at runtime. More here https://adonisjs.com/docs/4.0/logger#_switching_transports

I want to transport logs to 2 places at the same time though.

Write a service which writes to multiple transport

Hm, seems to be such a popular use case, I am surprised the solution is not easier.

It is common, for example, in production to log to:

  1. Console (just in case)
  2. Loggly (everything)
  3. Sentry (warnings and errors only)

Maybe, but it’s hard to incorporate all use cases in the core. That’s why community packages exists

But my understanding was that logger is based on Winston, which already supports multiple transports. That interface, however, was obscured by the config file and I am not sure if it’s possible to add extra ones?

Logger is not based on Winston, each transport is. You can write a new transport, that uses pino over Winston and it will work fine.

For your use case, you can simply write a new transporter that logs to multiple areas

@moltar What did you end up doing? I agree, multiple transports is base requirement, and I’m surprised we have to add it ourselves.

@virk Can you describe your recommended solution again? Why is pino a part of it?

Thanks