iojs / electron – 将所有内容输出到文件中

我目前正在使用iojs 2.3.1在Electron中构build一个应用程序,并且我想要做的是在dev工具控制台中输出打印出来的任何内容和所有内容。

在早期版本的节点中,以前可以通过stdout / stderr进行pipe道操作,这已经不再可行了,而且我不能在我的生活中find一个可行的解决scheme,而且不需要更改大量的代码。

有没有人有这个工作的解决scheme? 谢谢!

最终的工作结果是使用温斯顿一个快速的变化,使其与电子工作。 https://github.com/dustinblackman/winston

编辑:

由于这个答案仍然在被观察,这个解决scheme更好。 https://github.com/dustinblackman/winston-electron

你可以像这样创build一个自定义控制台:

 var output = fs.createWriteStream('./stdout.log'); var errorOutput = fs.createWriteStream('./stderr.log'); // custom simple logger var logger = new Console(output, errorOutput); // use it like console var count = 5; logger.log('count: %d', count); // in stdout.log: count 5 

请参阅https://iojs.org/api/console.html#console_new_console_stdout_stderr


显然,exception不会打印到错误日志,这是一个解决方法:

 process.on('uncaughtException', function (err) { logger.error('Caught exception: ' + err); });