I'm using SLF4J for logging messages in my Java project and building 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?
View -> Tool Windows -> Build. There is small "ab" button on the left panel. All gradle logs for current build are there.
Project contains annotation processor which generates java code during compilation. By default, gradle outputs generated source files into build/classes directory.
We create the Logger instance by using the LoggerFactory class and its getLogger method and providing the name of the class. That way we bind the logger to the class name which gives us the context of the log message. Once we have that, we can use the Logger methods to create LogRecord on a given level.
Developers just need to include the logging framework dependency in the classpath and SLF4J will utilize it to append the logs. If no logging dependency is provided on the classpath, it will default to a no-operation implementation and nothing gets logged.
Add this to your build script:
logging.captureStandardOutput LogLevel.INFO
Then run your build with "-i"
gradle -i
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With