winston version?_winston@2winston@3 node -v outputs:_ v10.9.0We 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 https://github.com/winstonjs/winston/issues/1269
@senseysensor that is absolutely a supported feature of winston@3. This is used in several examples, but is not _(surprisingly)_ not documented in our README.md. The canonical example would be in ./examples/quick-start.js. But to summarize, each Transport accepts a format. e.g.:
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 Error objects. See #1338.
Most helpful comment
@senseysensor that is absolutely a supported feature of
winston@3. This is used in several examples, but is not _(surprisingly)_ not documented in ourREADME.md. The canonical example would be in./examples/quick-start.js. But to summarize, eachTransportaccepts a format. e.g.: