-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Different formatter for different transports #1567
Comments
@senseysensor that is absolutely a supported feature of const { createLogger, format, transports } = require('../');
const logger = createLogger({
level: 'info',
//
// All Transports get:
// - Timestamp
// - Error handling (i.e. logger.log(new Error('loloksure')))
// - String interpolation
//
format: format.combine(
format.timestamp({
format: 'YYYY-MM-DD HH:mm:ss'
}),
format.errors({ stack: true }),
format.splat()
),
defaultMeta: { service: 'your-service-name' },
transports: [
//
// File transports serialize to JSON
//
new transports.File({
format: format.json(),
filename: 'quick-start-error.log',
level: 'error'
}),
new transports.File({
format: format.json()
filename: 'quick-start-combined.log'
}),
//
// Console transport is colored and simply
// formatted.
//
new transports.Console({
format: format.combine(
format.colorize(),
format.simple()
)
})
]
}); |
Beware that this feature is not entirely working correctly for |
* winstonjs#1567: document common transport options * Update README.md
Is formatting not supported for |
@egalvan10 Same here |
I'm also having issues with applying formatting to the Http transport while the other ones are working. |
Please tell us about your environment:
winston
version?winston@2
winston@3
node -v
outputs: v10.9.0What is the problem?
We need to have possibility to configure different formatter for each transport. As is described here on SO: https://stackoverflow.com/q/32968838/1002036
It should be obvious that we don't want to have the same formatter for console (i.e., string with padding and colors) and for, for example, mongoDB (json object). So for the moment the only solution I can see is to make some wrappers that would call different loggers, each with single transport and formatter.
Probably is a bit related to #1269
The text was updated successfully, but these errors were encountered: