【问题标题】:Node JS - Winston is not logging anything to log fileNode JS - Winston 没有将任何内容记录到日志文件中
【发布时间】:2017-06-16 11:11:53
【问题描述】:

这里是代码示例:

   var winston = require('winston');
   var loggerNew = new (winston.Logger)({
   transports: [
       new winston.transports.File({filename: 'all-logs.log'})
   ],
   exceptionHandlers: [
      new winston.transports.File({filename: 'exceptions.log'})
   ]
   });

我正在使用 winston 模块来记录预期。但它没有将任何内容写入文件。请指教!

【问题讨论】:

  • 我运行您的代码没有任何问题,并且它已创建日志文件。你是怎么登录的?
  • 你如何运行你的代码?文件名是相对于进程位置创建的,尝试将文件名更改为require("path").join(__dirname,"all-logs.log")
  • @ParhamAlvani :我使用的代码与我在此处发布的代码相同。你能告诉我你的node版本和winston版本吗?

标签: node.js logging winston


【解决方案1】:
winston.exceptions.handle(
  new winston.transportsConsole(),
  new winston.transports.File({ filename: 'logs/test.log' })
);

throw new Error('Exception Handler');

试试这个。

【讨论】:

    猜你喜欢
    • 2019-01-03
    • 1970-01-01
    • 2018-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-29
    • 2015-04-15
    • 1970-01-01
    相关资源
    最近更新 更多