简体   繁体   English

如何使用 Sequelize 正确设置 Winston 登录?

[英]How to set up Winston loggin with Sequelize properly?

I am configuring winston with Sequelize.我正在用 Sequelize 配置winston。 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 }),
  ],
});

https://stackoverflow.com/a/48573091/11343720 https://stackoverflow.com/a/48573091/11343720

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM