Home » Java » Enterprise Java » Spring: Setting Logging Dependencies

About Jerome Versrynge

Jerome Versrynge

Spring: Setting Logging Dependencies

This post describes how to set-up logging dependencies in Spring. It is based on information available in a post by Dave Syer’s. A reminder on Java logging frameworks is available here. The code example is available at GitHub in the Spring-Logging-Dependencies directory.

Spring uses Jakarta Commons Logging API (JCL). Unfortunately, many people do not like its runtime discovery algorithm. We can disactivate it and use SLF4J with Logback instead. We will use a variation of the Spring MVC with Annotations example to do so.

Here is the modified controller:

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

public class MyController {

    private static final Logger LOG
        = LoggerFactory.getLogger(MyController.class);

    @RequestMapping(value = '/')
    public String home(Model model) {

        String s = 'Logging at: ' + System.currentTimeMillis();

        model.addAttribute('LogMsg', s);

        return 'index';



We create a SFL4J logger and log some information with current time in milliseconds.

The maven dependencies are:






Once built, one can start the example by browsing:
http://localhost:9393/spring-logging-dependencies/. It will display the following:

In the logs, you will find the logged statement:

More Spring posts here.

Reference: Setting Logging Dependencies In Spring from our JCG partner Jerome Versrynge at the Technical Notes blog.

(0 rating, 0 votes)
You need to be a registered member to rate this.
Start the discussion Views Tweet it!
Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to the Terms and Privacy Policy
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Inline Feedbacks
View all comments