How to configure Lo4j in a Spring Boot project

Asked

Viewed 1,055 times

0

The goal of setting up log4j is to see the logs of selects that Hibernate does on the eclipse consoles.

I already made configuration of Log4j in Spring MVC, but when I went to perform the same procedure in Spring Boot did not work.

I did it this way;

First I put the log4j.xml file in the package src/main/Resources

See how the file turned out

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
<Configuration status="WARN">
    <Appenders>
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout pattern="%d{HH:mm:ss.SSS} %-5level %logger{36}: %msg%n" />
        </Console>
    </Appenders>

    <Loggers>

        <Logger name="org.hibernate.SQL" level="debug"/>

        <Root level="info">
            <AppenderRef ref="Console" />
        </Root>
    </Loggers>
</Configuration>

As it didn’t work I thought it would have been due to the lack of Libraries, so I added these lines of code in pom.xml

<dependency>
   <groupId>org.apache.logging.log4j</groupId>
   <artifactId>log4j-api</artifactId>
   <version>2.5</version>
</dependency>
<dependency>
   <groupId>org.apache.logging.log4j</groupId>
   <artifactId>log4j-core</artifactId>
   <version>2.5</version>
</dependency>
<dependency>
   <groupId>org.apache.logging.log4j</groupId>
   <artifactId>log4j-jcl</artifactId>
   <version>2.5</version>
</dependency>

But it still didn’t work.

When having the first configuration problems can find this tutorial below;

Click here

I accept suggestions.

1 answer

1


You need to add the following configuration to application.properties:

spring.jpa.properties.hibernate.show_sql=true
  • wow, thank you, it worked, I’m trying to relocate myself in the job market and I already know how to handle Spring MVC, at least I think I know né rsrs, and I started studying Spring Boot now, think what sensational is the Spring Boot, thank you very much.

  • 1

    @wladyband certainly made a great choice in studying Spring Boot. Good luck!

  • sorry to bother you, but I still haven’t solved the problem, in fact it is emitting SQL logs, but it is doing so by a Spring Boot feature and not because of the Log4j feature, I delete Log4j and still continued to send SQL logs. I need Log4j because it provides me with far more resources than the native features of Spring Boot.

  • ready, just solved the problem, the solution was here in this post, a look >>>>> http://stackoverflow.com/questions/25683210/spring-boot-logging-with-log4j2

Browser other questions tagged

You are not signed in. Login or sign up in order to post.