简体   繁体   English

使用Azure调试Node.js

[英]Debugging Node.js with Azure

I have been fooling around with Node.js and Azure. 我一直在鬼混Node.js和Azure。 I have created a simple worker role which supports socket connections. 我创建了一个简单的辅助角色,它支持套接字连接。 I'm trying to debug my application but don't really know how, since it is essentially a socket server. 我正在尝试调试我的应用程序,但实际上并不知道如何操作,因为它本质上是一个套接字服务器。 To make matters worse I haven't figured out a way to write to console or log data within this worker role. 更糟的是,我还没有找到一种方法可以在此辅助角色中写入控制台或记录数据。 I'm hoping that someone has figure out a good way to go about debugging Node.js in Azure. 我希望有人找到了一种在Azure中调试Node.js的好方法。 Thanks for the help in advanced. 感谢您的帮助。

When i was initially developing under Nodejs as a socket server too, i was directly running and debugging node.exe from WebStorm so it was acceptable to just console.log() or util.inspect() and see activity happen on WebStorm's console window. 当我最初也在Nodejs下作为套接字服务器进行开发时,我是直接从WebStorm运行和调试node.exe,因此可以只使用console.log()或util.inspect()并在WebStorm的控制台窗口上查看活动。

Of course when we deploy to Windows Azure that was not going to help as there appeared to be no way to see the runtime console window of the launched node.exe process in the server even if we remote desktop in. After trying out a couple of logging libraries, the only one that actually could save to a file was log4js. 当然,当我们部署到Windows Azure时,这无济于事,因为即使远程进入桌面,似乎也无法看到服务器中已启动的node.exe进程的运行时控制台窗口。日志库,实际上唯一可以保存到文件的库是log4js。

I have a logger object which is exposed to the rest of the application, so they do not have to know about the actual implementation library. 我有一个暴露给应用程序其余部分的logger对象,因此他们不必了解实际的实现库。

var log4js = require('log4js');

// The logger helper utilises log4js under the covers.
// Serves as a wrapper from the rest of the application.
log4js.replaceConsole();
log4js.configure({
    appenders: [
        { type: 'console' },
        { type: 'file', filename: 'log/socket.log', category: 'socket' }
    ]
});
var logger = log4js.getLogger('socket');

So the information will be logged to the E: or F:\\approot\\log\\socket.log file in the deployed server. 因此,该信息将记录到已部署服务器中的E:或F:\\ approot \\ log \\ socket.log文件中。

Then use a tailing program like baretail to observe the real-time activity as they get logged. 然后用尾矿程序像baretail观察实时活动,因为他们得到记录。

if you're running in the emulator, you can see your logs in the Emulator GUI (right click on the emulator icon). 如果您在仿真器中运行,则可以在仿真器GUI中查看日志(右键单击仿真器图标)。 If you're running in Azure, your best bet is to log to a blob storage. 如果您在Azure中运行,最好的选择是登录到Blob存储。 You can also enable remote desktop to access Windows Azure VM remotely. 您还可以启用远程桌面以远程访问Windows Azure VM。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM