【问题标题】:logging the console to file in electron将控制台记录到电子文件中
【发布时间】:2019-01-25 01:11:44
【问题描述】:

我正在创建一个在我的桌面上运行的电子应用程序。由于我不会从控制台运行它,因此我想将标准 console 交换为 nodejs 写入流以将其写入文件。我能够想出这个

var logStream=fs.createWriteStream("log.txt",{flags:"a+"});
console.log(logStream);
logStream.write(new Date().toString() +"\r");
console=new console.Console({stdout:logStream,stderr:logStream});

这就是当代码在 node.js 中运行时运行得非常好时事情变得奇怪的地方。然而,在电子中,它给出了错误TypeError: Console expects a writable stream instance,但logStream.write(new Date().toString() +"\r"); 运行得很好,所以很明显它是一个可写的流实例。这只是电子故障还是有办法解决这个问题。

【问题讨论】:

    标签: node.js electron fs


    【解决方案1】:

    也许你已经找到了,但是, 在阅读此https://github.com/nodejs/node/issues/21366

    尝试用console=new console.Console(logStream,logStream);替换console=new console.Console({stdout:logStream,stderr:logStream});

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-18
      • 1970-01-01
      • 1970-01-01
      • 2015-07-26
      • 1970-01-01
      相关资源
      最近更新 更多