NodeJS记录器:winston.transports.DailyRotateFile不是函数 [英] NodeJS Logger: winston.transports.DailyRotateFile is not a function

查看:568
本文介绍了NodeJS记录器:winston.transports.DailyRotateFile不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用NodeJS和express编写rest api,并且正在使用express-winston记录访问和错误.但是我想每天分开日志.就像在此帖子

I'm writing a rest api with NodeJS and express and I'm using express-winston to log accesses and erros. But I want to separate de log daily. Like in this post

我正在尝试使用winston.transports.DailyRotateFile.下面是一段代码.

I'm trying to do so with winston.transports.DailyRotateFile. A piece of code below.

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不是函数

Then I receive the error: winston.transports.DailyRotateFile is not a function

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

I guess I have to install another pack, since reading winston's doc I found that you can write custom transports.

您是否需要有关我必须安装哪个软件包的信息?我发现有一些不匹配或已停产.

Would you have information on which package I would have to install? I found some that doesn't match or was discontinued.

感谢您的帮助

推荐答案

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

I had to do this so it would work:

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

我已经拥有正确的程序包,但它直到之前都不起作用我在上面写了几行.

I already had the right package but it wouldn't work, until I wrote the lines above.

这篇关于NodeJS记录器:winston.transports.DailyRotateFile不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆