在Winston中记录普通文件 [英] Plain file logging in winston

查看:227
本文介绍了在Winston中记录普通文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想将数据记录到文件中,而不要将日志级别,时间戳等记录到文件中.

I want to log just the data and not log level, timestamp etc. to a file.

var logger = new (winston.Logger)({                                                                                     
  transports: [                                                                                                     
    new (winston.transports.File)({                                                                                 
        filename: '/tmp/data.log',                                                                                  
        json : false,                                                                                               
        timestamp : function() {                                                                                    
            return '';                                                                                              
        }                                                                                                           
    })                                                                                                              
  ]                                                                                                                 
}); 

logger.log('info', "a")

它从行中删除了时间戳,但是日志级别仍然出现.当前,文件包含"info:a".我希望它只记录"a".是否可以在Winston中指定输出格式?

It removes the timestamp from the line but log level still appears. Currently, file contains "info: a". I want it to log just "a". Is it possible to specify output format in winston?

推荐答案

不幸的是,这种格式已硬编码到winston中.您可以在common.jslog函数中看到它的逻辑,大多数默认传输都使用该函数.

Unfortunately, that formatting is sort of hardcoded into winston; you can see the logic for it in the log function of common.js, which is used by most of the default transports.

解决此问题的方法是编写自己的不依赖common.log()的自定义传输方式.

The way around this would be to write your own custom transport which doesn't rely on common.log().

顺便说一句:您可以提供timestamp: false选项以禁用默认传输中的时间戳记录.

An aside: you can just provide a timestamp: false option to disable timestamp logging in the default transports.

这篇关于在Winston中记录普通文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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