How do you view SLF4J logging output from project source during a Gradle build?
I'm using SLF4J for logging messages in my Java project and 开发者_如何学JAVAbuilding the project with Gradle. I'm trying to debug something and I'd like to be able to see logging messages that are in my Java source code or unit tests. Is there a way to get that output to the console?
Add this to your build script:
logging.captureStandardOutput LogLevel.INFO
Then run your build with "-i"
gradle -i
You can determine the logging level and therefore the output by providing a command line parameter (-i
for INFO, -d
for DEBUG). For more information please refer to the chapter about logging in the Gradle user manual. Needless to say that only the logging messages will show up of code that actually gets executed during the build.
Example:
gradle build -i
I had the same issue in a library without any SLF4J implementation. For me, it was not not a gradle problem.
I was missing this log message :
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder"
Adding Logback at testCompile
or testImplementation
solved my problem :
testImplementation 'ch.qos.logback:logback-classic:1.1.7'
For Maven users, you should solve it with (I didn't test):
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.7</version>
<scope>test</scope>
</dependency>
精彩评论