Open lburgazzoli opened 6 years ago
Hi! Any response?
This code is responsible for logger creation: https://github.com/testcontainers/testcontainers-java/blob/23478fac6f86c4dd8d0eb964386089144cb26f6e/core/src/main/java/org/testcontainers/utility/DockerLoggerFactory.java#L11-L25
I don't have any experience how to leverage MDC in the context, so an example or a PR (or just PR draft) would be helpful.
This is a possible example:
https://gist.github.com/lburgazzoli/2bfc2a1ed7967e9f80b236f5e0e881b4
As MDC
relies on ThreadLocal
and I do not know the threading model used by testcontainers
, I've decorated the Logger
instance so that diagnostic info are added on each invocation if they are done in a new thread.
I've not tested it as building testcontainers-java
fails for the following reason:
$ ./gradlew install
> Task :bom:verifyLombok FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':bom:verifyLombok'.
> Verification of Lombok JAR failed!
Local JAR file: /home/lb/.gradle/caches/modules-2/files-2.1/org.projectlombok/lombok/1.18.2/524e0a697e9d62950b2f763d88d35cd8dc82a9a1/lombok-1.18.2.jar
Expected checksum: c5178b18caaa1a15e17b99ba5e4023d2de2ebc18b58cde0f5a04ca4b31c10e6d
Actual checksum: f13db210efa2092a58bb7befce58ffa502e5fefc5e1099f45007074008756bc0
Even after having deleted the gradle cache.
A new version with a proxy which reduce the amount of code:
https://gist.github.com/lburgazzoli/cedc572465061994827a48682b6ba6e4
@lburgazzoli I like this suggested improvement, and I think the proxy-based approach is a good idea.
Are you still having problems with the Lombok JAR in your local build? That is a strange issue...
It fails when using
./gradlew install -x check
but it succeed with
./gradlew publishToMavenLocal -x
So by default test containers logs in the following form:
So if I want to log only warning I have to configure i.e. log4j2 as follow:
Which means that I have to include:
So if I do upgrade the image or if I need to test against different images, I have to change also the logging configuration if I do not want to see
testcontainers
logs.Maybe it is better to put the image name using MDC so one may decide to show it or not.