Logging to multiple transports


#1

Is it possible to log to multiple transports?

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


#2

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


#3

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


#4

Write a service which writes to multiple transport


#5

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)

#6

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


#7

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?


#8

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