Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

context.log vs console.log in Azure function apps

In the nodejs examples for Azure function apps, there is a passed in context obj to the function and it is possible to do context.log in the same manner as you can with console.log to output messages.

What is the difference between these two methods and does it matter which you use? Thx.

like image 981
yen Avatar asked Feb 22 '19 16:02

yen


People also ask

What is context log?

Context.Log (Method) Directs the DataFile object associated with the Context to log the values of the Context.

How do I check logs on Azure function app?

To view streaming logs in the portal, select the Platform features tab in your function app. Then, under Monitoring, choose Log streaming. 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.

What is the best practice to be followed in order to improve the performance of Azure function?

To reduce latency, create the storage account in the same region as the function app. To improve performance in production, use a separate storage account for each function app. This is especially true with Durable Functions and Event Hub triggered functions.

Where are Azure function logs stored?

By default, the data collected from your function app is stored in Application Insights. In the Azure portal, Application Insights provides an extensive set of visualizations of your telemetry data. You can drill into error logs and query events and metrics.


1 Answers

This documentation should answer your question :)

In Functions, you use the context.log methods to write trace output to the console. In Functions v2.x, trace outputs using console.log are captured at the Function App level. This means that outputs from console.log are not tied to a specific function invocation, and hence aren't displayed in a specific function's logs. They do, however, propagate to Application Insights. In Functions v1.x, you cannot use console.log to write to the console.

Long story short - context.log is best!

like image 195
Marie Hoeger Avatar answered Sep 22 '22 07:09

Marie Hoeger