-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Gradle tests (with JBoss LogManager setup) output duplicate unformatted messages #22844
Comments
Strange, /cc @Ladicek PS: This also happens with current |
Test reports are ok. I think this comes from the gradle test task which tries to output logging but shouldn't. We can deactivate this behavior directly in the plugin. |
I think so too. Gradle seems to try and capture logging (by installing it's own JUL handler) and apparently has no way of disabling this feature. This feature seems pretty needless (idiotic?) considering they already capture stdout/stderr and that's where JUL logs end up by default. |
I tried differend configuration but nothing change. I asked a question on their forum. |
@glefloch did anything come of this from the Gradle forums? I tried searching there as well but didn't find any related conversations. edit: found the forum question and there was no response :/ |
@glefloch With Previously, we just were not adding the JBoss LogManager (the messages were mostly useless without formatting) and this worked around the issue; although did miss printing configured test logging (e.g. errors). With Updated Quarkus we needed a fix and did a bit of investigation and came up with a workaround. Basically Gradle 8.4 is adding a The fix/workaround is to walkthrough the list of handler's in the root logger and wrap any Here's the extension (Kotlin): class LoggingFixExtension: BeforeAllCallback {
override fun beforeAll(context: ExtensionContext) {
val logger = LogManager.getLogManager().getLogger("")
val handlers = logger.handlers.clone()
handlers.forEach {
if (it.javaClass.simpleName == "SLF4JBridgeHandler") {
logger.removeHandler(it)
logger.addHandler(FormattingFixHandler(it))
}
}
}
} Here's the handler (Kotlin): class FormattingFixHandler(val wrapped: Handler): Handler() {
override fun publish(record: LogRecord) {
@Suppress("DEPRECATION")
val preparedRecord =
if (record is ExtLogRecord && record.formatStyle != ExtLogRecord.FormatStyle.NO_FORMAT) {
val formatted = ExtLogRecord(record)
formatted.setMessage(record.formattedMessage, ExtLogRecord.FormatStyle.NO_FORMAT)
formatted
} else {
record
}
wrapped.publish(preparedRecord)
}
override fun flush() {
wrapped.flush()
}
override fun close() {
wrapped.close()
}
} Note: It uses the deprecated This is working for now but there's a couple ways this might be tackled by Quarkus to provide a proper logging experience in Gradle.
This seems like the most obvious fix.
Quarkus should be able to apply this fix. It could be as simple as shipping the above JUnit 5 extension and using its service loader registration functionality to add the handler (that's actually how we are installing it currently). |
FYI... All the above workaround does is fix the formatting of the messages. The messages are logged "bare" (no level, thread, etc.). It's as if somebody did I'm not sure exactly what Gradle is supposed to be printing, it might be exactly that or it might be that the log record is still being mishandled. |
I spent the morning digging through Gradle sources trying to find some way to disable this behavior, or work around it, with no luck; instead, I'm trying an approach to make the JBoss LogManager more friendly towards "legacy" handlers/formatters. See jboss-logging/jboss-logmanager#449 for more info. |
That's great! From looking at the code this is essentially my workaround implemented directly via LogManager, correct? Asking, cause this would validate my workaround as being "correct" until this lands in Quarkus. |
Yes, essentially, with the added benefit that it will "fix" other handlers as well. |
The upstream patch is merged. I will ask James for a logmanager release as soon as |
Thanks for the help! I'm sure many Gradle users out there will praise this haha |
This avoids the situation where `printf`-formatted messages are translated to "simple" messages due to quarkusio#22844.
Fixes quarkusio#36919. Fixes quarkusio#22844. (cherry picked from commit 47f0c58)
This avoids the situation where `printf`-formatted messages are translated to "simple" messages due to quarkusio#22844. (cherry picked from commit d6e8ae3)
Describe the bug
When Gradle tests are setup to use the JBoss LogManager (as suggested in the test logging guide using
systemProperty "java.util.logging.manager", "org.jboss.logmanager.LogManager"
). Gradle will output unformatted raw messages to stdout during testing.For example, this log statement in an application:
will produce the following output during
./gradlew (build|test)
:It should be noted that Gradle hides stdout/stderr from tests by default. So the
Hello %s
is a duplicate, if you look at thestdout
output of the actual test you will see a proper log line with the messageHello World!
.Expected behavior
Log messages should be output once (and never be unformatted) during build and/or teest.
Actual behavior
Log messages are duplicated and unformatted during build and/or test.
How to Reproduce?
code-with-quarkus.zip
Output of
uname -a
orver
MacOS 12.1
Output of
java -version
Java 17
GraalVM version (if different from Java)
No response
Quarkus version or git rev
2.6.2.Final
Build tool (ie. output of
mvnw --version
orgradlew --version
)Gradle 7.3.3
Additional information
No response
The text was updated successfully, but these errors were encountered: