11

In Spring, it is possible to set the Logging Category Level via environment variables. I've tried the same in a Quarkus application with the following logger declaration:

package org.my.group.resteasyjackson;

public class JacksonResource {

  private static final Logger LOGGER = LoggerFactory.getLogger(JacksonResource.class);
  
  @GET
  public Set<Quark> list() {
    LOGGER.info("Hello");
    return quarks;
  }
}

Executing the build artifact with

QUARKUS_LOG_CATEGORY_ORG_MY_LEVEL=WARN java -jar my-artifactId-my-version-runner.jar

will log anything at info level (since it is the default), therefore the "Hello" message.

However, inserting

quarkus.log.category."org.my".level=WARN

in the application.properties file works as desired. Are environment variables in this use case not usable for Quarkus applications?

Sincostan
  • 361
  • 2
  • 11
  • 1
    did you manage to make it working? I have the same problem. I also try to use that like "QUARKUS_LOG_CATEGORY__ORG_MY__LEVEL" with additional underscore for quote sign, but it does not help either. – Mimas Mar 05 '21 at 12:26

3 Answers3

13

Just tried with quarkus 1.13.1 and adding extra underscores for the quotes seems to work, try:

QUARKUS_LOG_CATEGORY__ORG_MY__LEVEL=WARN

Steven Hawkins
  • 538
  • 1
  • 4
  • 7
  • And remember it only applies to package, cannot reach class level, same as Spring Boot. See [here](https://stackoverflow.com/questions/34181094/set-logging-level-in-spring-boot-via-environment-variable/57623996#comment135274919_57623996). For Quarkus 2.16 and Openshift 3 I confirm it is working. – WesternGun Jul 20 '23 at 13:19
1

You can do this:

quarkus.log.category."org.my".level=${LOG_LVL:INFO}

This simply means: use the log-level from my env variable "LOG_LVL" and if this is not present use INFO as default.

You can set this variable either as an env.variable or pass it through as system parameter during startup, but I'm not sure about the syntax as system parameter.

Serkan
  • 639
  • 5
  • 14
0

You should be able to use a system property (!= environment variable) like this:

java -Dquarkus.log.category.\"org.my\".level=WARN ...

Note: system properties will overrwite their application.properties, except for a quarkus.profile due to a bug.

No idea if environment variables can overwrite them too. Maybe the " need to be escaped. (I find environment variables brittle, I prefer system properties.)

Geoffrey De Smet
  • 26,223
  • 11
  • 73
  • 120