I need a different types of formatters for each transport.
Example:
logger = new (winston.Logger)({
transports: [
new (winston.transports.LogstashUDP)({
// some config here. Do noting on formatting
}),
new (winston.transports.Mail)({
// do formatting one way
}),
new (winston.transports.File)({
// write to file as json (maybe format it here)
}),
new (winston.transports.Console)({
// do another formatting
})
]
});
As i can see from winston transports docs only Console supports custom formatter.
I'm using winston-mailer
module for mail and winston-logstash-upd
Is there any way to solve this with Winston? Or maybe how to create wrapper around one of these modules to support formatting?
Here's the solution posted to GitHub by dandv
const logger = winston.createLogger({
transports: [
new winston.transports.File({
filename: 'error.log', level: 'error',
format: winston.format.simple(),
}),
new winston.transports.File({
filename: 'combined.log', level: 'debug',
format: winston.format.printf(info => `${new Date().toISOString(), ${info.message}`),
}),
],
});
logger.error('prefixed by the timestamp only in `combined.log`');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With