Skip to content

Commit

Permalink
Configurable log-level for tests (#910)
Browse files Browse the repository at this point in the history
* Default log level for tests is always `INFO`
* Can be overridden with the Maven argument '-Dtest.log.level=NEW_LEVEL`, e.g. '-Dtest.log.level=WARN` to reduce most of it
  • Loading branch information
snazy authored Mar 8, 2021
1 parent 5d9b75e commit 71241c6
Show file tree
Hide file tree
Showing 11 changed files with 181 additions and 6 deletions.
30 changes: 30 additions & 0 deletions clients/deltalake/core/src/test/resources/logback-test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
Copyright (C) 2020 Dremio
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<configuration debug="true">
<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator"/>
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%date{ISO8601} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root>
<level value="${test.log.level:-INFO}"/>
<appender-ref ref="console"/>
</root>
</configuration>
4 changes: 2 additions & 2 deletions clients/deltalake/spark2/src/test/resources/logback-test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
<pattern>%date{ISO8601} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<logger name="org.apache.spark.sql.delta" level="DEBUG"/>
<logger name="org.apache.spark.sql.delta" level="${test.log.level:-INFO}"/>
<root>
<level value="warn"/>
<level value="${test.log.level:-INFO}"/>
<appender-ref ref="console"/>
</root>
</configuration>
4 changes: 2 additions & 2 deletions clients/deltalake/spark3/src/test/resources/logback-test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
<pattern>%date{ISO8601} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<logger name="org.apache.spark.sql.delta" level="DEBUG"/>
<logger name="org.apache.spark.sql.delta" level="${test.log.level:-INFO}"/>
<root>
<level value="warn"/>
<level value="${test.log.level:-INFO}"/>
<appender-ref ref="console"/>
</root>
</configuration>
30 changes: 30 additions & 0 deletions clients/hmsbridge/core/src/test/resources/log4j2-test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2020 Dremio
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="${sys:test.log.level:-INFO}">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>
30 changes: 30 additions & 0 deletions clients/hmsbridge/core/src/test/resources/logback-test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
Copyright (C) 2020 Dremio
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<configuration debug="true">
<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator"/>
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%date{ISO8601} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root>
<level value="${test.log.level:-INFO}"/>
<appender-ref ref="console"/>
</root>
</configuration>
4 changes: 4 additions & 0 deletions servers/quarkus-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

<properties>
<quarkus.smallrye-openapi.store-schema-directory>${project.build.directory}/openapi</quarkus.smallrye-openapi.store-schema-directory>
<test.log.level>INFO</test.log.level>
</properties>

<dependencies>
Expand Down Expand Up @@ -188,6 +189,9 @@
<configuration>
<systemPropertyVariables>
<maven.home>${maven.home}</maven.home>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<quarkus.log.level>${test.log.level}</quarkus.log.level>
<quarkus.log.console.level>${test.log.level}</quarkus.log.console.level>
</systemPropertyVariables>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.net.URLClassLoader;
import java.util.Map;
import java.util.Properties;
import java.util.logging.LogManager;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
Expand Down Expand Up @@ -107,6 +108,9 @@ public class QuarkusAppStartMojo extends AbstractQuarkusAppMojo {
@Parameter
private Properties outputProperties;

@Parameter(defaultValue = "true")
private boolean resetJavaUtilLogging;

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
if (isSkipped()) {
Expand Down Expand Up @@ -139,6 +143,13 @@ public void execute() throws MojoExecutionException, MojoFailureException {
// Use MavenProject classloader as parent classloader as Maven classloader hierarchy is not linear
final URLClassLoader mirrorCL = new URLClassLoader(urls, MavenProject.class.getClassLoader());

String oldLogManager = System.getProperty("java.util.logging.manager");
if (resetJavaUtilLogging) {
// Quarkus uses the JBoss LogManager, have to set it
System.setProperty("java.util.logging.manager", "org.jboss.logmanager.LogManager");
LogManager.getLogManager().reset();
}

final AutoCloseable quarkusApp;
try {
Class<?> clazz = mirrorCL.loadClass(QuarkusApp.class.getName());
Expand Down Expand Up @@ -173,6 +184,16 @@ public void execute() throws MojoExecutionException, MojoFailureException {
quarkusApp.close();
} finally {
mirrorCL.close();

if (resetJavaUtilLogging) {
// Quarkus uses the JBoss LogManager, have to set it
if (oldLogManager == null) {
System.getProperties().remove("java.util.logging.manager");
} else {
System.setProperty("java.util.logging.manager", oldLogManager);
}
LogManager.getLogManager().reset();
}
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion versioned/jgit/src/test/resources/logback-test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</encoder>
</appender>
<root>
<level value="info"/>
<level value="${test.log.level:-INFO}"/>
<appender-ref ref="console"/>
</root>
</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</encoder>
</appender>
<root>
<level value="info"/>
<level value="${test.log.level:-INFO}"/>
<appender-ref ref="console"/>
</root>
</configuration>
30 changes: 30 additions & 0 deletions versioned/tiered/gc/src/test/resources/logback-test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
Copyright (C) 2020 Dremio
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<configuration debug="true">
<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator"/>
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%date{ISO8601} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root>
<level value="${test.log.level:-INFO}"/>
<appender-ref ref="console"/>
</root>
</configuration>
30 changes: 30 additions & 0 deletions versioned/tiered/mongodb/src/test/resources/logback-test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
Copyright (C) 2020 Dremio
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<configuration debug="true">
<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator"/>
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%date{ISO8601} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root>
<level value="${test.log.level:-INFO}"/>
<appender-ref ref="console"/>
</root>
</configuration>

0 comments on commit 71241c6

Please sign in to comment.