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
Allow configuring formats per-transport within the same logger #1401
Comments
Nevermind, this is indeed possible, but the documentation completely omits mentioning the feature. 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`'); |
Definitely add to docs plz |
@dandv The printf code in your comment does not work out of the box, there is a missing closing brace after the timestamp code. So this line...
...needs a closing brace like so
Thanks for the code and knowledge for custom formatting! Much appreciated! |
@dandv what if I have another format outside of transports and inside the create logger method. Which format will be applied? |
The one inside. |
What's the feature?
I have a logger with a console transport, and another transport that goes to a cloud-based logging service. For the console, I want to prefix messages with a timestamp, and colorize them. For the cloud-based logging service, I don't want timestamps because the service provides its own, and I don't want colors either.
Is this a feature you're prepared to implement, with support from us?
PRs for this feature were already sent: #427 and #422
Is configuring formats per transport already possible, but I haven't seen that capability explained in the README?
The text was updated successfully, but these errors were encountered: