Skip to content

Commit

Permalink
Apply min-level logging config to root logger quarkusio#20066
Browse files Browse the repository at this point in the history
(cherry picked from commit 190df7e)
  • Loading branch information
galderz authored and gsmet committed Nov 30, 2021
1 parent 3187c08 commit 4c0b474
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,14 @@ public void initializeLogging(LogConfig config, LogBuildTimeConfig buildConfig,
final LogContext logContext = LogContext.getLogContext();
final Logger rootLogger = logContext.getLogger("");

rootLogger.setLevel(config.level);
if (config.level.intValue() < buildConfig.minLevel.intValue()) {
log.warnf("Root log level %s set below minimum logging level %s, promoting it to %s",
config.level, buildConfig.minLevel, buildConfig.minLevel);

rootLogger.setLevel(buildConfig.minLevel);
} else {
rootLogger.setLevel(config.level);
}

ErrorManager errorManager = new OnlyOnceErrorManager();
final Map<String, CleanupFilterConfig> filters = config.filters;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* and only messages at same runtime log level or above are shown.
*/
@QuarkusTest
@QuarkusTestResource(SetRuntimeLogLevels.class)
@QuarkusTestResource(SetCategoryRuntimeLogLevels.class)
public class LoggingMinLevelAboveTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* and there's no applicable runtime log level override.
*/
@QuarkusTest
@QuarkusTestResource(SetRuntimeLogLevels.class)
@QuarkusTestResource(SetCategoryRuntimeLogLevels.class)
public class LoggingMinLevelByDefaultTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package io.quarkus.it.logging.minlevel.unset;

import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.is;

import org.junit.jupiter.api.Test;

import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;

/**
* Tests that logging works as expected when min-level is default,
* and the global log level is below it.
*/
@QuarkusTest
@QuarkusTestResource(SetGlobalRuntimeLogLevel.class)
public class LoggingMinLevelGlobalTest {

@Test
public void testInfo() {
given()
.when().get("/log/bydefault/info")
.then()
.statusCode(200)
.body(is("true"));
}

@Test
public void testWarn() {
given()
.when().get("/log/bydefault/warn")
.then()
.statusCode(200)
.body(is("true"));
}

@Test
public void testNotTrace() {
given()
.when().get("/log/bydefault/not-trace")
.then()
.statusCode(200)
.body(is("true"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* it will be automatically promoted to DEBUG.
*/
@QuarkusTest
@QuarkusTestResource(SetRuntimeLogLevels.class)
@QuarkusTestResource(SetCategoryRuntimeLogLevels.class)
public class LoggingMinLevelPromoteTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import io.quarkus.test.common.QuarkusTestResourceLifecycleManager;

public final class SetRuntimeLogLevels implements QuarkusTestResourceLifecycleManager {
public final class SetCategoryRuntimeLogLevels implements QuarkusTestResourceLifecycleManager {

@Override
public Map<String, String> start() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.quarkus.it.logging.minlevel.unset;

import java.util.HashMap;
import java.util.Map;

import io.quarkus.test.common.QuarkusTestResourceLifecycleManager;

public final class SetGlobalRuntimeLogLevel implements QuarkusTestResourceLifecycleManager {

@Override
public Map<String, String> start() {
final Map<String, String> systemProperties = new HashMap<>();
systemProperties.put("quarkus.log.level", "TRACE");
return systemProperties;
}

@Override
public void stop() {
}

}

0 comments on commit 4c0b474

Please sign in to comment.