azure node.js console.log不能login到stdout或stderr文件
我有一个azure(应用程序服务)node.js应用程序。 node.js使用以下模块
"scripts": { "start": "node bin\/www", "test": "mocha" }, "dependencies": { "async": "^1.5.2", "bluebird": "^3.3.4", "express": "^4.13.3", "ioredis": "^1.15.1", "lodash": "^4.6.1", "socket.io": "^1.4.5" }, "devDependencies": { "chai": "^3.5.0", "socket.io-client": "^1.4.5" }
我想启用应用程序的日志logging,所以我设置环境variablesDEBUG = *使用入口 – >configuration – >应用程序设置。 从那时起,应用程序的快速和lockinglogging开始出现在/ LogFiles / Application文件夹中,其名称为xxxxxx-nnnn-stderr-nnnnnnnnnnnnnn.txt
我在我的应用程序的lib文件夹中的一个文件中添加了一个console.log语句
function MessageActions(redis, io) { ... } MessageActions.prototype.routeMessage = function(message) { console.log('routeMessage: ' + JSON.stringify(message)); //this is not appearing anywhere in logs var self = this; return Promise.join( self.checkUserMessage(message), self.checkGroupMessage(message), function(sendtarget, sendgroup) { if(!sendtarget && !sendgroup) { var pmsg = util.inspect(message); throw new Error('Failed to route message: ' + pmsg); } } ); }
我相信这个函数被调用,因为我可以看到stderr文件中的下面的错误
[错误:无法路由消息:{…}]
但是我无法find在这个stderr文件的任何地方添加了console.log的日志语句。 另外,/ LogFiles / Application文件夹中没有标准输出文件。
如何添加日志语句以及在哪里检查?
我的IISNode.yml文件有以下两行loggingEnabled:true devErrorsEnabled:true
请尝试将“ Application Logging (Filesystem)
设置为启用以启用stream日志function。
之后,您将在/ LogFiles / Application文件夹中find多个日志文件,其中包含console.log()
的输出,其名称为xxxxxx-nnnn-stdout-nnnnnnnnnnnnnn.txt
。
但请注意描述:
启用应用程序日志logging以从您的Web应用程序代码收集诊断跟踪 您需要启用此function才能启用stream日志function。 此设置在12小时后自动closures。
要在Node.js应用程序中保留一个持久化日志文件,可以使用一些node.js日志库,如winston 。
有一种方法可以查看控制台的输出,如果你采取以下步骤:
- 在Azure门户中打开网站刀片
- 点击工具图标
- 点击“Visual Studio Online”工具
- 将工具切换到“开”
…等待分机启用
- 点击工具切换下的“Go->”图标。
- 一旦Visual Studio Online“Monaco”窗口启动,您可以“运行”您的应用程序,该应用程序会在另一个窗口中显示您的网站,但是您的“Monaco”窗口将从您的应用程序中输出控制台。
希望这有助于find你的问题。
在你的Index.js / Messages中,replace下面的代码:
if (useEmulator) { var restify = require('restify'); var server = restify.createServer(); server.listen(3978, function() { console.log('test bot endpoint at http://localhost:3978/api/messages'); }); server.post('/api/messages', connector.listen()); } else { module.exports = { default: connector.listen() } }
有:
if (useEmulator) { var restify = require('restify'); var server = restify.createServer(); server.listen(3978, function() { console.log('test bot endpoint at http://localhost:3978/api/messages'); }); server.post('/api/messages', connector.listen()); } else { var listener = connector.listen(); var withLogging = function(context, req) { console.log = context.log; listener(context, req); } module.exports = { default: withLogging } }
这将覆盖console.log函数。 希望这会有所帮助
- 我如何将一个更快的语言与Express.js后端集成?
- Node.js上的Azure Easy API'没有注册'/ api / xxx'的路由?
- 部署到云时,无法将实体添加到node.js中的azure色存储表中?
- 通过Visual Studio部署到Azure Cloud Service时,未设置环境variables
- 我可以通过复制文件在Azure节点应用程序服务器上部署node.js吗?
- 如何正确读取表存储绑定的数据?
- 在Node js的Azure表存储中插入实体时,请添加PartitionKey
- Azure托pipe的节点应用程序无法find模块“async / each”
- 从自定义node.js API中检索Azure Blob