I am configuring winston with Sequelize. I have the following:
const logger = winston.createLogger({
level: 'info',
format: winston.format.json(),
transports: [
new winston.transports.File({ filename: path.join('logs', 'error.log'), level: 'error' }),
new winston.transports.File({ filename: path.join('logs', 'info.log'), level: 'info' }),
new winston.transports.File({ filename: path.join('logs', 'combined.log') }),
],
});
const sequelize = new Sequelize(
database.database,
database.user,
database.password,
{
host: database.host,
dialect: 'mysql',
logging: (msg) => logger.info(msg),
}
);
However, the logs files show the message before level:
{"message":"Database connection has been established successfully.","level":"info"}
Besides, timestamp does not appear as shown here .
Any fix?
const logger = winston.createLogger({
level: 'info',
format: winston.format.combine(winston.format.timestamp(), winston.format.json()),
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
transports: [
new winston.transports.File({ filename: path.join('logs', 'error.log'), level: 'error', timestamp: true }),
new winston.transports.File({ filename: path.join('logs', 'info.log'), level: 'info', timestamp: true }),
new winston.transports.File({ filename: path.join('logs', 'combined.log'), timestamp: true }),
],
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.