Node.js 中的日志轮换?

编程入门 行业动态 更新时间:2024-10-28 12:24:43
本文介绍了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.0、log.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 中的日志轮换?

本文发布于:2023-07-26 14:27:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1216698.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:日志   Node   js

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!