前言

[Azure 筆記] 前言


原文

Enable diagnostic logging


App services 有很多不同的 logging
它們均有不同的功能和限制
它們分別是

  • Application logging
  • Web server logging
  • Detailed error messages
  • Failed request tracing
  • Deployment logging

Application logging

可存放位置

  • Windows
    • App Service file system
    • Azure Storage blobs
  • Linux / Container
    • App Service file system

相關的設置可以在 App Service logs 中進行設定
這是由 application 產生的 log
共分為 5 個 category,分別是 Critical, Error, Warning, Info, Debug, Trace.

在 application 內使用自帶的 logging facilities 即可把 logging 寫到 application log
例如在 ASP.NET 中可以使用 System.Diagnostics.Trace

System.Diagnostics.Trace.TraceError("If you're seeing this, something bad happened");

Python 則是可以使用 OpenCensus package

Application logging (Windows)

可選用 Application Logging (Filesystem)Application Logging (Blob)同時選用兩者

要注意思的是
Filesystem 內的 log 只能被用作 debug
在啟用後 12 小時會被自動關閉
Blob 的 log 則會被長期保存

Logging 的 level 和這些 category 相對應

LevelIncluded categories
DisabledNone
ErrorError, Critical
WarningWarning, Error, Critical
InformationInfo, Warning, Error, Critical
VerboseTrace, Debug, Info, Warning, Error, Critical (all categories)

Application logging (Linux/Container)

如果你用的是 Linux / Container app
你就只能把你的 application log 寫到 File System
你可以設置佔用空間上限 (Quota, MB)
也可以設置保留多少天的 log (Retention Period, Days)

 

Web server logging

可存放的位置

  • Windows
    • App Service file system
    • Azure Storage blobs
  • Linux
    • N/A

依從 W3C extended log file formatraw HTTP request data
包含了 HTTP method, resource URI, client IP, client port, user agent, response code 等資訊

你可以選擇存放到 Storage (Blob) 或 File system
也可以設定保留多少天的 log (Retention Period, Days)

 

Other logging

App Service 還有其他的 log
下面這個列表就列出了所有支援的 log
((我懶得翻譯總結了,大家將就點看吧 🤭

Application logging

Platform: Windows, Linux
Location: App Service file system and/or Azure Storage blobs
Description: Logs messages generated by your application code. The messages are generated by the web framework you choose, or from your application code directly using the standard logging pattern of your language. Each message is assigned one of the following categories: Critical, Error, Warning, Info, Debug, and Trace.

Web server logging

Platform: Windows
Location: App Service file system or Azure Storage blobs
Description: Raw HTTP request data in the W3C extended log file format. Each log message includes data like the HTTP method, resource URI, client IP, client port, user agent, response code, and so on.

Detailed error messages

Platform: Windows
Location: App Service file system
Description: Copies of the .html error pages that would have been sent to the client browser. For security reasons, detailed error pages shouldn’t be sent to clients in production, but App Service can save the error page each time an application error occurs that has HTTP code 400 or greater.

Failed request tracing

Platform: Windows
Location: App Service file system
Description: Detailed tracing information on failed requests, including a trace of the IIS components used to process the request and the time taken in each component. One folder is generated for each failed request, which contains the XML log file, and the XSL stylesheet to view the log file with.

Deployment logging

Platform: Windows, Linux
Location: App Service file system
Description: Helps determine why a deployment failed. Deployment logging happens automatically and there are no configurable settings for deployment logging.


Stream logs

App service 也有提供 stream log 的功能
只要是存放到 /LogFiles directory (d:/home/logfiles)
((文檔中另一個位置也標了 /home/LogFiles,不肯定那一個才對,這個位置應該是只適用於 Linux / Container app。至於 D drive 的那個大概應該是只適用於 Windows app
的 .txt, .log, or .htm 檔都會被 stream

你可經由以下途徑來查看被 stream 的 log

Azure portal

在你的 app 中打開 Log stream 即可查看

Azure CLI

你可以用 log 指令來查看 app 的log
也可以用 tail 來做 streaming
下面是一個例子

az webapp log tail --name appname --resource-group myResourceGroup

 

Access Log file

Azure Storage

如果你選擇了把 log 放到 Azure Storage
你需要使用 Azure Storage 的 storage tool (e.g. Azure Storage Explorer)

File system

但如果你的 log file 是寫進了你的 App Service file system
你可以經由指定的 URL 直接下載你的 log 的 ZIP file

  • Linux/container apps: https://<app-name>.scm.azurewebsites.net/api/logs/docker/zip
  • Windows apps: https://<app-name>.scm.azurewebsites.net/api/dump

ZIP 檔會包含了 docker host 和 docker container 存放在 /home/LogFiles 的 logs
如果該 app 不止一個 instance 的話
該 ZIP 檔也會包含所有 instance 的 logs

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *


Trending