Overriding function log level not working

47 Views Asked by At

I have an Azure Function with an HTTP Trigger (Java, Runtime Version ~4) and want to override the logging level of this specific function:

@FunctionName("Stores")
public HttpResponseMessage getStores(
            @HttpTrigger(...
...
    context.getLogger().log(Level.FINE, "Test message with level " + Level.FINE);
...

I can set a function-specific log level in the host.json, this works fine (locally and in the cloud):

  "logging": {
    "logLevel": {
      "Function.Stores.User": "Trace"
    }
  }

Overriding the log level in the local.settings.json works fine when I use the following syntax:

"AzureFunctionsJobHost__logging__logLevel__Function.Stores.User": "Trace"

Note, that I can't replace the dots in the part Function.Stores.User with double underscores as documented in https://learn.microsoft.com/en-us/azure/azure-functions/configure-monitoring?tabs=v2. It seems that this part in the documentation is wrong.

But when I add the setting AzureFunctionsJobHost__logging__logLevel__Function.Stores.User with value Trace to the application settings in the cloud portal, it has no effect.

Is this a bug or is there anything wrong with my settings?

1

There are 1 best solutions below

0
Pavan On

that I can’t replace the dots in the part Function.Stores.User with double underscores as documented

You should be able to override the host.json values by creating equivalent application settings with specific formatting.

  • The dots in the host.json paths should indeed be replaced by double underscores.
  1. Host.json path: logging.logLevel.default

    • App setting: AzureFunctionsJobHost__logging__logLevel__default
  2. Host.json path: logging.logLevel.Host.Aggregator

    • App setting: AzureFunctionsJobHost__logging__logLevel__Host__Aggregator
  3. Host.json path: logging.logLevel.Function

    • App setting: AzureFunctionsJobHost__logging__logLevel__Function
  4. Host.json path: logging.logLevel.Function.Function1

    • App setting: AzureFunctionsJobHost__logging__logLevel__Function__Function1
  5. Host.json path: logging.logLevel.Function.Function1.User

    • App setting: AzureFunctionsJobHost__logging__logLevel__Function__Function1__User

There are no apparent issues with the above settings you provided. There might be a bug issue or an unexpected behavior in the Azure Functions environment.

  • Check with this SO link which I have gone through as similar as with your requirement.

I have tried with these below settings.

host.json

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    },
    "logLevel": {
      "Function": "Error",
      "Function_http_trigger": "Information"
    }
  },
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[4.*, 5.0.0)"
  }
}

enter image description here