How to redirect all logs from hibernate and spring to log4j2?

hibernate, java, log4j, spring, tomcat

Solution

This worked perfectly for me:

<properties>
    <logger.version>2.0-rc1</logger.version>
</properties>

    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>${logger.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        <version>${logger.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-1.2-api</artifactId>
        <version>${logger.version}</version>
    </dependency>
    <dependency>
    <!--HIBERNATE-SPRING - LOGGER (log4j)-->
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.7.6</version>
    </dependency>

Problem

I build my "superWebApp" with the next technology stack: ``` persistence provider - Hibernate 4.x webMvc and beans container - Spring 4.x web containter - Tomcat 7.5.x ``` I have a task to write all logs to db. And it would be a pain to do it for each logging framework separately. That's why I need to redirect all logs to single framework and then using a DBAppender wouldn't be a problem. I was thinking about log4j2, since I use it to write logs in "superWebApp". So is there any idea how to redirect all logs from hibernate and spring to log4j2? (it would be good to redirect tomcat loogs too)? If it is not possible, maybe there is another logging framework that can be central?

Original source

Related problems