Node.js 中的日志轮换? [英] Log Rotation in Node.js?

查看:56
本文介绍了Node.js 中的日志轮换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的网络分析中,我将数据记录在纯文本文件中.我想每天轮换日志,因为它记录了太多数据.目前我正在使用 bunyan 来旋转日志.

In my web analytics, I am logging the data in plain text file. I want to rotate the log on a daily basis because its logging too much data. Currently I am using bunyan to rotate the logs.

我面临的问题

它正确地旋转了文件,但是旋转的日志文件的名称是 log.0log.1 等.我希望文件名是 <代码>log.05-08-2013, log.04-08-2013

It is rotating the file correctly, but rotated log file are in the name log.0, log.1, etc. I want the file name to be log.05-08-2013, log.04-08-2013

我无法编辑 bunyan 包的源代码,因为我们正在通过 NPM 使用 package.json 安装模块.

I can't edit the source of the bunyanpackage because we are installing the modules using package.json via NPM.

所以我的问题是 - Node.js 中是否还有其他符合我要求的日志轮换?

So my question is - Is there any other log rotation in Node.js that meets my requirement?

推荐答案

Winston does 支持在文件名中使用日期进行日志轮换.看看 this pull request,它添加了该功能并在四个月前合并.不幸的是,该文档未在网站上列出,但还有另一个拉取请求待处理解决这个问题.根据该文档以及日志轮换功能的测试,您应该能够将其添加为新传输以启用日志轮换功能.类似于以下内容:

Winston does support log rotation using a date in the file name. Take a look at this pull request which adds the feature and was merged four months ago. Unfortunately the documentation isn't listed on the site, but there is another pull request pending to fix that. Based on that documentation, and the tests for the log rotation features, you should be able to just add it as a new Transport to enable the log rotation functionality. Something like the following:

winston.add(winston.transports.DailyRotateFile, {
  filename: './logs/my.log',
  datePattern: '.dd-MM-yyyy'
});

这篇关于Node.js 中的日志轮换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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