azure-functions-core-tools icon indicating copy to clipboard operation
azure-functions-core-tools copied to clipboard

Allow for the `UserLogDefaultLogLevel` to be set independent of system logs

Open liliankasem opened this issue 8 months ago • 2 comments

Description

In Core Tools today, the log level for user logs can only be set as the same value of system logs via the "default" property in host.json:

https://github.com/Azure/azure-functions-core-tools/blob/bb4c949899cd5659d6bfe8b92cc923453a2e8f88/src/Azure.Functions.Cli/Diagnostics/LoggingFilterHelper.cs#L34-L38

https://github.com/Azure/azure-functions-core-tools/blob/bb4c949899cd5659d6bfe8b92cc923453a2e8f88/src/Azure.Functions.Cli/Common/Utilities.cs#L237

And this is the only way to control the logs that user's can see when they run their application.

This is frustrating as you won't be able to see your debug logs without also seeing all of the debug logs coming from the system, and there is no way to filter those out.

Proposal

We can fix this either by

a) exposing a way for customers to set UserLogDefaultLogLevel without having to set the default log level, and/or without having to also set the SystemLogDefaultLogLevel to the same value. This could be through something like a flag i.e. --userLogLevel Debug, or environment setting. I would advise against this being a host.json setting.

b) implement a way for us to respect the settings coming from workers. For example, in dotnet-isolated, you can set the min log level in your Program.cs:

builder.Logging.SetMinimumLevel(LogLevel.Debug);

Is there a way we can respect this setting without having to make customers manually configure UserLogDefaultLogLevel as well?

I did also find that instead of setting the log level in Program.cs - you can also use appsettings.json; Core Tools(?) is respecting any appsettings.json file that is provided without any additional config, however logLevel in host.json is still required.

This might be future work rather than immediate fix, but with the Core Tools refactor we are thinking about tools for each stack, and part of that could include logging management per stack.

Considerations

  1. We often tell customers, and document, that host.json is only used to control host logs, and not worker logs. So it is confusing that you have to set the host log level to control your worker logs. I think we need a mechanism outside of host.json to control this.

  2. My understanding is that this is an issue that only impacts local development so there shouldn't be need for changes in the workers

  3. How do other workers outside of dni allow customers to configure their logging setttings? Does that need to be taken into account?

liliankasem avatar Mar 12 '25 00:03 liliankasem