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

Various fixes for logging issues: #1066

Merged
merged 1 commit into from
Feb 27, 2019
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
8 changes: 8 additions & 0 deletions build-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1418,6 +1418,14 @@
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemProperties>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
</systemProperties>
</configuration>
</plugin>
<plugin>
<groupId>${project.groupId}</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
Expand Down
5 changes: 5 additions & 0 deletions devtools/common/src/main/resources/templates/pom-template.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<configuration>
<systemProperties>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
Expand Down
10 changes: 9 additions & 1 deletion docs/src/main/asciidoc/getting-started-guide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -297,16 +297,24 @@ In the generated `pom.xml` file, you can see 2 test dependencies:

Quarkus supports https://junit.org/junit4/[Junit 4] and https://junit.org/junit5/[Junit 5] tests.
In the generated project, we use Junit 5.
Because of this, the version of the https://maven.apache.org/surefire/maven-surefire-plugin/[Surefire Maven Plugin] must be set, as the default version does not support Junit 5:
Because of this, the version of the https://maven.apache.org/surefire/maven-surefire-plugin/[Surefire Maven Plugin] must
be set, as the default version does not support Junit 5:

[source,xml,subs=attributes+]
----
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.version}</version>
<configuration>
<systemProperties>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
</systemProperties>
</configuration>
</plugin>
----

We also set the `java.util.logging` system property to make sure tests will use the correct logmanager.

The generated project contains a simple test.
Edit the `src/test/java/org/acme/quickstart/GreetingResourceTest.java` to match the following content:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import java.util.Deque;
import java.util.logging.Formatter;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.jboss.logmanager.ExtHandler;
import org.jboss.logmanager.ExtLogRecord;
Expand Down Expand Up @@ -195,13 +197,28 @@ private synchronized void activate() {
// Always attempt to drain the queue
ExtLogRecord record;
while ((record = logRecords.pollFirst()) != null) {
Logger logger = Logger.getLogger(record.getLoggerName());
if (getLevel(logger).intValue() > record.getLevel().intValue()) {
//this category has an explicit level set and this is too low to log
continue;
}
if (isEnabled() && isLoggable(record)) {
publishToChildren(record);
}
}
activated = true;
}

private Level getLevel(Logger logger) {
while (logger != null) {
if (logger.getLevel() != null) {
return logger.getLevel();
}
logger = logger.getParent();
}
return Level.ALL;
}

private void publishToChildren(final ExtLogRecord record) {
for (Handler handler : handlers) {
handler.publish(record);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ quarkus.security.file.enabled=true
web-message=A message
schedulerservice.cron.expr=0/10 * * * * ?

quarkus.log.category.kafka.level=WARN
quarkus.log.category.\"org.apache.kafka\".level=WARN
quarkus.log.category.\"org.apache.zookeeper\".level=WARN