温斯顿:如何旋转日志 [英] Winston: how to rotate logs

查看:80
本文介绍了温斯顿:如何旋转日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Winston处理node.js的日志时,如何旋转日志.也就是说,如何在应用运行的每一天创建一个新文件?

How can I rotate logs when using Winston to handle logging for node.js. That is, how can I create a new file for each day the app runs?

    var logger = new (winston.Logger)({
       transports: [
          new (winston.transports.Console)(),
          new (winston.transports.File)({ filename: '2012-07-09.log' })
      ]
});

logger.log('info', 'Test Log Message', { anything: 'This is metadata' });

推荐答案

winston的作者和维护者.

每天登录一个新文件是当前的一项开放功能请求: https://github.com /flatiron/winston/issues/10 .很想看到有人实施它.

Logging to a new file everyday is currently an open feature request: https://github.com/flatiron/winston/issues/10. Would love to see someone implement it.

也就是说,还有其他选择:

That said, there are other options:

  1. 文件传输接受maxsize选项,当日志文件超过一定大小(以字节为单位)时,它将旋转日志文件.

  1. The File transport accepts a maxsize option which will rotate the logfile when it exceeds a certain size in bytes.

还有一个带有新传输方式的开放请求请求,我还没有机会真正研究过"fileRotate",似乎这种基于日期的轮换是这样的:

There is also an open pull-request with a new transport I haven't had a chance to really dig into "fileRotate", which it seems does this kind of date-based rotation: https://github.com/flatiron/winston/pull/120/files

这篇关于温斯顿:如何旋转日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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