NodeJS 记录器:winston.transports.DailyRotateFile 不是函数

NodeJS Logger: winston.transports.DailyRotateFile is not a function

我正在使用 NodeJS 和 express 编写 rest api,我正在使用 express-winston 来记录访问和错误。但我想每天分开de log。喜欢这个 post

我正尝试使用 winston.transports.DailyRotateFile 这样做。下面一段代码。

api.use(expressWinston.logger({
    transports: [
      new winston.transports.DailyRotateFile({
          name: 'file',
          datePattern: '.yyyy-MM-ddTHH',
          filename: path.join(__dirname, "log-access", "log_file.log")
      })
    ]
})); 

然后我收到错误:winston.transports.DailyRotateFile 不是函数

我想我必须安装另一个包,因为阅读 winston 的文档后我发现您可以编写自定义传输。

你能知道我必须安装哪个软件包吗?我发现有些不匹配或已停产。

感谢您的帮助

您要找的是this module

只需按照文档进行操作即可。

我必须这样做才能起作用:

var winston = require('winston'), expressWinston = require('express-winston');
winston.transports.DailyRotateFile = require('winston-daily-rotate-file');

我已经有了正确的 package 但它不起作用,直到我写了上面的几行。

您不需要分配:

var winston = require('winston'), expressWinston = require('express-winston');
winston.transports.DailyRotateFile = require('winston-daily-rotate-file');

你只需要require它:

const winston = require('winston');
require('winston-daily-rotate-file');