问题
I deployed my nodeJs bot to Bot Service recently, and i can't seems to figure out how to generate and view it's logs.
- when i try to enable logging, i constantly getting an unknown error
- Looking at the log files on the server, there is no file who logs the node application
- Tried to log to Application insights, without success.
help?
回答1:
Assuming your bot is hosted through Azure via an App Service, you should be able to see logging from your NodeJS application by performing the following steps:
Enabling Logging
- Click on the App Service box on your Azure dashboard, or navigate to the resource via the top search bar.
- In the side menu, under Monitoring, navigate to Diagnostic logs.
- Make sure that Application Logging (Filesystem) is turned on.
- Now, in the root directory of your NodeJS application \site\wwwroot, you want to create a file named IISNode.yml and inside of it write the line
loggingEnabled: true
. This will enable your application to writestderr
andstdout
to the log stream. - From here, you just need to access the log stream of your application, and there are 3 ways.
Accessing the Log Stream
Personally, I prefer using the Azure Command-Line Interface, which you can easily install using the node package manager or npm.
To install the Azure CLI, issue the following command on your terminal:
npm install -g azure-cli
or sudo npm install -g azure-cli
if you need root permission.
If you need more information on how to install the Azure CLI look here.
Now you have to log into your Azure account through the Azure CLI so that it can access your subscription. This is done via azure login
.
Once you have finished logging in through the command line, you need to switch to service management mode with the command azure config mode asm
.
Then you can use azure site list
to get a list of your current Azure sites.
In the list, find the site that you want the logs for, and find its name in the Name column. Then use the command azure site log tail <sitename>
and the terminal will start to output live logs straight from your application!
Other Options
The above method is only 1 of the 3 methods you can use to access these logs. If you want more information on the other 2 methods then follow this link.
That above link also contains a lot of the information I outlined in my post.
I hope this helped!
来源:https://stackoverflow.com/questions/41537711/cant-figure-out-how-to-generate-view-logs-for-nodejs-bot-on-bot-service