Azure / azure-functions-java-library

Contains annotations for writing Azure Functions in Java
MIT License
42 stars 42 forks source link

debug logging not working #149

Closed cepxy closed 3 years ago

cepxy commented 3 years ago

When executing a function we need to retrieve the Logger from the context-object to be able to peform logging. Whilst afaik the portal supports DEBUG, INFORMATION, WARNING and ERROR the Logger (java.util.logging.Logger) provides a more finegrained number of log levels. (although this outdated logger API is complicated to use in comparison to more modern slf4j-api but that's anther topic)

However, only info, warn and error are displayed in the functions log streaming or function monitoring: When the following log statements are executed during a function call

        context.getLogger().fine("context logtest fine");
        context.getLogger().finer("context logtest finer");
        context.getLogger().finest("context logtest finest");
        context.getLogger().info("context logtest info");
        context.getLogger().warning("context logtest warning");
        context.getLogger().severe("context logtest severe");

this is the result:

2021-03-23T11:37:52.625 [Information] context logtest info
2021-03-23T11:37:52.625 [Warning] context logtest warning
2021-03-23T11:37:52.625 [Error] context logtest severe

There is no debug-logging. "fine", "finer" and "finest" are missing.

Log level in logstream is set to verbose, default log level in host.json is set to "Debug"

{
  "version": "2.0",
  "logging": {
    "fileLoggingMode": "always",
    "logLevel": {
      "default": "Debug",
    }
  }
}

Why are the debug-log events missing? What needs to be configured to get it to work?

azure-functions-java-library 1.4.2

YusukeTobo commented 3 years ago

Aa far as I see in debugger, Logger creates FINE LogRecord, then trys to publish it to FuncitonsHost. https://github.com/Azure/azure-functions-java-worker/blob/976635d81a31f2464f8b5ca1925d91b6e1b139a2/src/main/java/com/microsoft/azure/functions/worker/WorkerLogManager.java#L110

So, we can adjust host log level by host.json below. it works for me.

{
  "version": "2.0",
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[2.*, 3.0.0)"
  },
  "logging": {
    "logLevel": {
      "default": "Trace"
    }
  }
}
cepxy commented 3 years ago

Thanks for the input. Got this to work in my test function.

I also just realized that I missed one loglevel of the java logging api, namely "config". And that's the one that gets translated into debug. >.<

context.getLogger().config("context logtest config"); --> 2021-04-01T10:37:24.755 [Debug] context logtest config

So from my observation the different loglevels should translate like this:

Azure Function JAVA Logging API Modern Java logging Frameworks like Slf4J, Log4j etc
Trace FINE, FINER, FINEST TRACE
Debug CONFIG DEBUG
Information INFO INFO
Warning WARNING WARN
Error SEVERE ERROR
Critical - FATAL

Might have helped though, to find this information somewhere in the documentation of azure functions with java ^^

Ticket can be closed. Thanks.