Azure App Service部署的Node.js应用console.log查看方法及输出位置
Hey there! I've got you covered on both questions about Node.js apps running on Azure App Service. Let's dive in.
When your Node.js app runs on Azure App Service, console.log() (and console.error()) output is captured by the platform and sent to two main destinations:
- Real-time log stream: Azure streams these logs live as your app generates them.
- Persistent log files: The logs are saved to your app's file system for later review.
By default, these log files are stored in:
- For Windows App Service plans:
D:\home\LogFiles\Application(look for files likenodejs.logor date-stamped log files) - For Linux App Service plans:
/home/LogFiles/Application(typically in files namednodejs.logor with timestamps)
These files rotate automatically based on your retention settings to avoid taking up too much storage.
There are several straightforward ways to access these logs, depending on whether you want real-time viewing or to check historical logs:
Option 1: Use the Azure Portal's Log Stream
- Navigate to your App Service resource in the Azure Portal.
- From the left menu, under Monitoring, select Log Stream.
- You'll see a live feed of your app's
console.logoutput, along with other platform logs. You can toggle between "Application logs" and other log types to filter what you see.
Option 2: Access logs via Kudu (SCM) Console
- Go to
https://<your-app-name>.scm.azurewebsites.net(replace<your-app-name>with your actual app's name). - From the top menu, select Debug console and choose either CMD (for Windows) or Bash (for Linux).
- Navigate to the log directory:
- Windows: Run
cd D:\home\LogFiles\Application - Linux: Run
cd /home/LogFiles/Application
- Windows: Run
- To view the latest logs, use commands like:
- Windows:
type nodejs.log - Linux:
cat nodejs.log
- Windows:
- You can also download individual log files directly from the Kudu file explorer interface.
Option 3: Use Azure CLI commands
If you prefer working in a terminal:
- Tail real-time logs: Run
az webapp log tail --name <your-app-name> --resource-group <your-resource-group>to stream logs live to your terminal. - Download logs to your local machine: Run
az webapp log download --name <your-app-name> --resource-group <your-resource-group>to download a zip file containing all your app's logs, which you can open and review locally.
Option 4: Use the App Service Editor
- In the Azure Portal, go to your App Service resource.
- Under Development Tools, select App Service Editor and click Go.
- In the editor, navigate to
LogFiles/Application(the full path varies by OS as mentioned earlier). - Click on the log file (like
nodejs.log) to open and view its contents directly in the browser.
Quick note: Ensure logging is enabled
If you don't see any logs, double-check that application logging is turned on:
- In the Azure Portal, go to your App Service > App Service logs (under Monitoring).
- For Application Logging (Filesystem), set the toggle to On, configure a retention period, and save your settings. This ensures logs are persisted to the file system.
内容的提问来源于stack exchange,提问作者developer7788

