0

I have tried different ways to configure logging in spring boot and took the help of different blogs but nothing seems to be working for me. I have specified log4j.properties in src/main/reosurces folder and executing the application, It creates the logs for me. BUT when I use external log4j.properties and provide below property while executing my application by jar

-Dlogging.config=/path/to/log4j.properties 

The log file is not getting generated. Below is snippet of my build.gradle file.

configurations.all { exclude group: 'com.sun.jdmk', module: 'jmxtools' exclude group: 'com.sun.jmx', module: 'jmxri' exclude group: 'ch.qos.logback', module: 'logback-classic' } 

What am I missing here ?

2
  • 1
    Spring Boot by default uses logback. So providing a log4j.properties isn't really going to help. You can specify log level simply in the application.properties. What is so special you need your own properties fie? Commented Oct 3, 2016 at 11:14
  • @M.Deinum I want external logging configuration. I have also tried logging.file and logging.path in application.properties. It is not working. I don't understand what am I missing here ? Commented Oct 3, 2016 at 13:17

1 Answer 1

1

Have a look at the spring-boot logging documentation: http://docs.spring.io/spring-boot/docs/current/reference/html/howto-logging.html

If you want to use log4j in combination with spring-boot, you need to exclude the default logging dependencies and add log4j as your logging framework.

<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-log4j2</artifactId> </dependency> 
Sign up to request clarification or add additional context in comments.

1 Comment

The OP is using gradle, so you should probably use that as an example rather than maven.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.