Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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?

like image 291
Matt W Avatar asked Apr 14 '11 22:04

Matt W


People also ask

How do I see gradle build log?

View -> Tool Windows -> Build. There is small "ab" button on the left panel. All gradle logs for current build are there.

Where is the output of gradle build?

Project contains annotation processor which generates java code during compilation. By default, gradle outputs generated source files into build/classes directory.

How do you write log in SLF4J?

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.

What is the default logging level in SLF4J?

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.


1 Answers

Add this to your build script:

logging.captureStandardOutput LogLevel.INFO

Then run your build with "-i"

gradle -i

like image 61
user452443 Avatar answered Oct 05 '22 02:10

user452443