練習 - 記錄
在此練習中,我們將探討用來檢視範例應用程式記錄的練習。
串流記錄練習
結尾記錄
在您現有的 Azure Cloud Shell 視窗中,使用下列命令來檢視應用程式執行個體的記錄:
az spring app logs --name customers-service
重要
如果您已關閉原始的 Azure Cloud Shell 視窗,或想要在您的本機開發環境中執行命令,您必須指定資源群組和 Azure Spring Apps 服務名稱:
az spring app logs --name customers-service --resource-group <resource group name> --service <service >instance name>
此命令將傳回記錄:
...
2021-04-23 09:13:59.516 INFO [customers-service,,,] 1 --- [ main] o.s.s.p.c.CustomersServiceApplication : Started CustomersServiceApplication in 48.032 seconds (JVM running for 79.933)
2021-04-23 09:14:05.385 INFO [customers-service,,,] 1 --- [nio-1025-exec-2] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2021-04-23 09:14:05.385 INFO [customers-service,,,] 1 --- [nio-1025-exec-2] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2021-04-23 09:14:05.410 INFO [customers-service,,,] 1 --- [nio-1025-exec-2] o.s.web.servlet.DispatcherServlet : Completed initialization in 25 ms
...
持續串流新的記錄
依預設,az spring app log tail
只會列印串流至應用程式主控台的現有記錄,然後結束。 如果您想要串流新的記錄,請新增 -f
(--follow
):
az spring app logs --name customers-service -f
錯誤和警告練習
接下來,我們會建立錯誤,以展現您如何可以快速偵錯並找出其根本原因的價值。
開啟 customers-service 並遵循記錄:
az spring app logs --name customers-service -f
接下來,在網頁瀏覽器中開啟新視窗,並使用下列命令觸發警告:(使用您的 Spring Apps 執行個體名稱來取代 "<spring-apps-name>")
https://<spring-apps-name>-api-gateway.azuremicroservices.io/api/customer/owners/George
存取上述 URL 會觸發警告,因為變數 "George" 無法轉換成數字來搜尋客戶。 您現在會看到類似以下畫面的警告:
若要解決此警告,請改為在網頁瀏覽器中使用客戶識別碼來搜尋客戶:
https://<spring-apps-name>-api-gateway.azuremicroservices.io/api/customer/owners/1