Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

logging.config configuration for spring boot

I wanted to configure location of log4j.xml file in my spring boot application. For that I have added logging.config property to my application.properties configuration, indicating log4j.xml file path. But seems this property is ignored. But it should work accorindg to spring boot docs:

logging.config= # location of config file (default classpath:logback.xml for logback)

Have I did something wrong?

like image 911
Aram Aslanyan Avatar asked Jul 01 '15 22:07

Aram Aslanyan


People also ask

How do I configure spring Boot logging?

Spring Boot has a LoggingSystem abstraction that attempts to configure logging based on the content of the classpath. If Logback is available, it is the first choice. You can also set the location of a file to which to write the log (in addition to the console) by using "logging. file".

Which logging does spring boot use?

Spring Boot uses Commons Logging for all internal logging but leaves the underlying log implementation open. Default configurations are provided for Java Util Logging, Log4J2, and Logback.

Which property will help in customizing default configuration for logging?

The various logging systems can be activated by including the appropriate libraries on the classpath and can be further customized by providing a suitable configuration file in the root of the classpath or in a location specified by the following Spring Environment property: logging. config .

What is the default logging level in spring boot?

INFO - INFO is the default logging level that is set by Spring Boot.


1 Answers

Spring Boot includes some starters that can be used if you want to exclude or swap specific technical facets. It's using logback by default, if you're gonna use log4j add spring-boot-starter-log4j in your classpath. For example, with maven it would be something like this:

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-log4j2</artifactId>
            <version>1.2.4.RELEASE</version>
</dependency>

and for log4j 1.x:

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-log4j</artifactId>
            <version>1.2.4.RELEASE</version>
</dependency>

Then add logging.config to your application.properties:

logging.config = classpath:path/to/log4j.xml
like image 53
Ali Dehghani Avatar answered Sep 19 '22 13:09

Ali Dehghani