gpt4 book ai didi

node.js - Winston日志模块中,为什么发送不同级别的日志不起作用

转载 作者:太空宇宙 更新时间:2023-11-04 03:11:05 27 4
gpt4 key购买 nike

在我的 Node 应用程序中,我使用 Winston 模块来存储我的应用程序日志。我尝试将日志存储在不同级别以及不同的文件中。在这种情况下,我收到错误“错误:传输已附加:文件”。

我的代码

  var winston=require('winston');
winston.add(winston.transports.File, { filename: './logfile.log',level:'error' });
winston.add(winston.transports.File, { filename: './logfile1.log',level:'warn' });
winston.add(winston.transports.File, { filename: './logfile2.log',level:'debug'});

winston.log('error', 'Error message!');//this should go to logfile.log
winston.log('warn', 'Warning message!');//this should go to logfile1.log
winston.log('debug', 'Debug message!');//this should go to logfile2.log

最佳答案

winston.add(winston.transports.File, { name:'log.error', filename: './logfile.log',level:'error' }); winston.add(winston.transports.File, { name:'log.warn', filename: './logfile1.log',level:'warn' }); winston.add(winston.transports.File, { name:'log.debug', filename: './logfile2.log',level:'debug'});

就这样吧!

关于node.js - Winston日志模块中,为什么发送不同级别的日志不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18612472/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com