Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure hibernate logging using log4j2.xml?

I recently switched to Apache log4j2, and still can not find a way to configure hibernate logging using log4j2.xml.

Because I can not find a way around this problem I still use log4j.properties file explicitly for hibernate. This is not the best solution since my log4j2.xml uses JPA appender (writes logs to db). I do not want to write separate logic for hibernate.

Is there a way to configure hibernate logging using log4j2?

like image 982
Yurii Bondarenko Avatar asked Jan 15 '14 17:01

Yurii Bondarenko


1 Answers

I found an answer to this question at: How to redirect all logs from hibernate and spring to log4j2?

Basically log4j2 doesn't work with Hibernate so you have to use log4j. But you still use your log4j2 configuration. You need the following dependencies and then the magic happens in the background.

<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <version>2.1</version>
</dependency>
<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-1.2-api</artifactId>
    <version>2.1</version>
</dependency>
<dependency>
<!--HIBERNATE LOGGER (log4j)-->
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
    <version>1.7.6</version>
</dependency>
like image 184
AllanT Avatar answered Oct 27 '22 08:10

AllanT