Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply min-level logging config to root logger #20373

Merged
merged 1 commit into from
Sep 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() {
}

}