Skip to content

Latest commit

 

History

History
94 lines (57 loc) · 5.31 KB

streaming-logs.md

File metadata and controls

94 lines (57 loc) · 5.31 KB
title description ms.date ms.topic ms.devlang ms.custom
Stream execution logs in Azure Functions
Learn how you can stream logs for functions in near real time.
8/21/2023
how-to
azurecli
devx-track-azurepowershell

Enable streaming execution logs in Azure Functions

While developing an application, you often want to see what's being written to the logs in near real time when running in Azure.

There are two ways to view a stream of log files being generated by your function executions.

  • Built-in log streaming: the App Service platform lets you view a stream of your application log files. This is equivalent to the output seen when you debug your functions during local development and when you use the Test tab in the portal. All log-based information is displayed. For more information, see Stream logs. This streaming method supports only a single instance, and can't be used with an app running on Linux in a Consumption plan. When your function is scaled to multiple instances, data from other instances isn't shown using this method.

  • Live Metrics Stream: when your function app is connected to Application Insights, you can view log data and other metrics in near real-time in the Azure portal using Live Metrics Stream. Use this method when monitoring functions running on multiple-instances and supports all plan types. This method uses sampled data.

Log streams can be viewed both in the portal and in most local development environments.

You can view both types of log streams in the portal.

To view streaming logs in the portal, select the Platform features tab in your function app. Then, under Monitoring, choose Log streaming.

Enable streaming logs in the portal

This connects your app to the log streaming service and application logs are displayed in the window. You can toggle between Application logs and Web server logs.

View streaming logs in the portal

To view the Live Metrics Stream for your app, select the Overview tab of your function app. When you have Application Insights enabled, you see an Application Insights link under Configured features. This link takes you to the Application Insights page for your app.

In Application Insights, select Live Metrics Stream. Sampled log entries are displayed under Sample Telemetry.

View Live Metrics Stream in the portal

To turn on the streaming logs for your function app in Azure:

  1. Select F1 to open the command palette, and then search for and run the command Azure Functions: Start Streaming Logs.

  2. Select your function app in Azure, and then select Yes to enable application logging for the function app.

  3. Trigger your functions in Azure. Notice that log data is displayed in the Output window in Visual Studio Code.

  4. When you're done, remember to run the command Azure Functions: Stop Streaming Logs to disable logging for the function app.

Use the func azure functionapp logstream command to start receiving streaming logs of a specific function app running in Azure, as in this example:

func azure functionapp logstream <FunctionAppName>

Note

Because built-in log streaming isn't yet enabled for function apps running on Linux in a Consumption plan, you need to instead enable the Live Metrics Stream to view the logs in near-real time.

Use this command to display the Live Metrics Stream in a new browser window.

func azure functionapp logstream <FunctionAppName> --browser

You can enable streaming logs by using the Azure CLI. Use the following commands to sign in, choose your subscription, and stream log files:

az login
az account list
az account set --subscription <subscriptionNameOrId>
az webapp log tail --resource-group <RESOURCE_GROUP_NAME> --name <FUNCTION_APP_NAME>

You can enable streaming logs by using Azure PowerShell. For PowerShell, use the Set-AzWebApp command to enable logging on the function app, as shown in the following snippet:

:::code language="powershell" source="~/powershell_scripts/app-service/monitor-with-logs/monitor-with-logs.ps1" range="19-20":::

For more information, see the complete code example.


Next steps