Quick question, but I can't find the answer in the...
# pact-jvm
b
Quick question, but I can't find the answer in the docs and ChatGPT isn't helpful either: how can I set the Pact verifier output log level to DEBUG in Java? In other languages it's a configuration setting in the code but I can't find the right syntax. Thanks 🙂
b
I have this question every time . . . and (obviously) forget it every time, too . . .
I think it's like a system property, or something? So how you change it depends on how you're launching it (e.g. mvn, gradle, etc)
b
Maven in my case. I've tried every possible permutation of
-Dpact.verifier.logLevel=DEBUG
but no success yet 😞
m
I’m no expert, but…. my recollection is that Pact just relies on the usual Java logging standards - so I think the answer is it depends. If you use
slf4j
or
logback
type thing, you just need to set the log level for the packages you care about in their config file. I think having a
logback-test.xml
like this in
src/test/resources
is all you need.
Copy code
<configuration>
    <include resource="org/springframework/boot/logging/logback/base.xml"/>
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
            </pattern>
        </encoder>
    </appender>
    <root level="info">
        <appender-ref ref="STDOUT"/>
    </root>
    <logger name="au.com.dius" level="debug"/>
</configuration>
The key thing is the bottom one that specifies the log level for he pact package. The rest is going to be specific to your setup, but that hopefully gets you on your way. Possibly even you could do this with spring application properties 🤷 TL;DR - don’t think about setting Pact’s log level, think about setting the log level for your logging framework for Pact.
b
Thanks, Matt, let me see if that works. Re: the terminology, is this a Java-specific comment? Because I'm used to configuring the output log level like this in C#:
Copy code
var Config = new PactConfig
{
    PactDir = pactDir,
    LogLevel = PactLogLevel.Debug,
};
which is why I explicitly said 'Pact log level' 🙂 I didn't know Pact-JVM simply relies on the logger underneath the test
m
Yeah, that’s correct. I think it’s a result of a few things, one being that we try to make each language idiomatic. But that can be at conflict with consistency for other languages (and probably in this case, not consistent with .NET idioms).
b
Adding that .xml file to the
src/test/resources
folder did the job, by the way, so thank you very much!
m
ok, nice!