javascript console.log() 没有出现在我的终端(nwjs)中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29496847/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
console.log() does not appear in my terminal (nwjs)
提问by arthurakay
In my nwjs app, I load a _launch.jsfile from an HTML file:
在我的 nwjs 应用程序中,我从一个 HTML 文件加载了一个_launch.js文件:
<html>
<body>
<script type="text/javascript" src="_launch.js"></script>
</body>
</html>
And in my _launch.jsfile, I fire up the the Node processes I need for an express server and socketIO.
在我的_launch.js文件中,我启动了快速服务器和 socketIO 所需的 Node 进程。
var express = require('express'),
app = express(),
server = require('http').Server(app),
io = require('socket.io')(server),
gui = require('nw.gui'),
__curDir = process.cwd(),
//keep the logic for the IO connections separate
ioServer = require(__curDir + '/server.js');
//configure Express to default web requests to /workspace/ folder
app.use(express.static(__curDir + '/workspace'));
ioServer.init(io, console);
server.listen(3000, function () {
console.log('HTTP server listening on *:3000');
window.location = 'http://localhost:3000/MyApp/';
});
The app launches just fine, and my express/socketIO connections are all perfectly working.
该应用程序启动得很好,我的 express/socketIO 连接都运行良好。
But while the console.log()in the server.listen() callback appears in my terminal, any messages I try to log from the server.jsfile (required earlier) never show up anywhere.
但是,虽然server.listen() 回调中的console.log()出现在我的终端中,但我尝试从server.js文件(之前需要)记录的任何消息都不会出现在任何地方。
Any ideas why?
任何想法为什么?
Per the nwjs wiki, any files loaded via require()should be running in the Node context (and mine otherwise appears to be) -- but for whatever reason, I cannot use console.log()to view logged information.
根据 nwjs wiki,任何通过require()加载的文件都应该在 Node 上下文中运行(我的其他文件似乎是)——但无论出于何种原因,我都无法使用console.log()查看记录的信息。
采纳答案by Serg de Adelantado
Please look at the list of changes related to nodein the nw.js wiki.
Since node-webkit supports GUI applications instead of console applications, the output of console.log() (and other similar methods such as console.warn() and console.error()) is redirected to WebKit's console. You may see it in your “Developer Tools” window (on its “Console” tab).
由于 node-webkit 支持 GUI 应用程序而不是控制台应用程序,console.log()(以及其他类似方法,如 console.warn() 和 console.error())的输出被重定向到 WebKit 的控制台。您可能会在“开发人员工具”窗口(在其“控制台”选项卡上)中看到它。
回答by Jakub Bejnarowicz
You have to run DevTools for Background Page by right clicking on your app and choosing the Inspect background pageoption from the context menu.
您必须通过右键单击您的应用程序并Inspect background page从上下文菜单中选择选项来运行 DevTools for Background Page 。
Here is a related bug report: 0.13-beta3 console.log doesn't work in node context
这是一个相关的错误报告:0.13-beta3 console.log 在节点上下文中不起作用
回答by ermenkoff
Just pass --enable-logging=stderr
in chromium-args
in your package.json:
只是通过--enable-logging=stderr
在chromium-args
你的package.json:
{
...
"chromium-args": "--enable-logging=stderr",
...
}
Or use the Inspect background page
DevTools as @Jakub Bejnarowiczhas pointed out.
或者Inspect background page
像@Jakub Bejnarowicz指出的那样使用DevTools 。