Spring Download Webapp: Get Hibernate to use log4j

I have a spring boot web application. Trying to set up registration. I understand the difference between slf4j and log4j. In this case, I need to use log4j. For the most part, it works the way I want.

The trick is that Hibernate prints SQL queries to the console and depending on the format, I think it doesn't use log4j at all. I would like to further customize what Hibernate registers. Most of the recommendations I see suggest that Hibernate is logged in through log4j. How do I get hibernation to use log4j as a logging framework?

I tried to exclude jboss logging, then I found out that jboss is actually a facade view like slf4j, so excluding it didn't seem to help solve the problem (and when I became particularly aggressive, the application failed to start)

I don't know yet how jboss or hibernate is configured. I am new to this, so I would really appreciate it if you included a sufficiently detailed description of how to implement the proposed solution.

Update: Someone asked, yes, I use Maven. I followed the instructions on the spring boot page to exclude the login so that log4j is used instead of spring loading. Now I'm sure most applications are logged in using log4j - either directly or through slf4j - as the system is configuring my log4j configuration file.

log4j , slf4j, , , . , Hibernate, . , , .

!

Maven: :

[INFO] [dependency:tree {execution: default-cli}]
[INFO] <redacted>
[INFO] +- <redacted>
[INFO] +- <redacted>
[INFO] |  +- log4j:log4j:jar:1.2.17:compile (version managed from 1.2.16)
[INFO] |  \- commons-codec:commons-codec:jar:1.3:compile
[INFO] +- <redacted>
[INFO] |  +- org.springframework:spring-context:jar:4.1.5.RELEASE:compile (version managed from 3.1.1.RELEASE)
[INFO] |  +- org.springframework:spring-beans:jar:4.1.5.RELEASE:compile
[INFO] |  +- org.springframework:spring-orm:jar:4.1.5.RELEASE:compile (version managed from 3.1.1.RELEASE)
[INFO] |  |  \- org.springframework:spring-jdbc:jar:4.1.5.RELEASE:compile
[INFO] |  +- org.slf4j:slf4j-api:jar:1.7.10:compile (version managed from 1.5.11)
[INFO] |  +- org.slf4j:jcl-over-slf4j:jar:1.7.10:compile (version managed from 1.5.11)
[INFO] |  +- org.slf4j:slf4j-log4j12:jar:1.7.10:compile (version managed from 1.5.11)
[INFO] |  \- c3p0:c3p0:jar:0.9.1:compile
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:1.2.2.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter:jar:1.2.2.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot:jar:1.2.2.RELEASE:compile
[INFO] |  |  \- org.springframework.boot:spring-boot-autoconfigure:jar:1.2.2.RELEASE:compile
[INFO] |  |     \- org.yaml:snakeyaml:jar:1.14:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.4.5:compile
[INFO] |  |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.4.5:compile (version managed from 2.4.0)
[INFO] |  |  \- com.fasterxml.jackson.core:jackson-core:jar:2.4.5:compile
[INFO] |  +- org.hibernate:hibernate-validator:jar:5.1.3.Final:compile
[INFO] |  |  +- javax.validation:validation-api:jar:1.1.0.Final:compile
[INFO] |  |  \- com.fasterxml:classmate:jar:1.0.0:compile
[INFO] |  +- org.springframework:spring-core:jar:4.1.5.RELEASE:compile
[INFO] |  +- org.springframework:spring-web:jar:4.1.5.RELEASE:compile
[INFO] |  \- org.springframework:spring-webmvc:jar:4.1.5.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-log4j:jar:1.2.2.RELEASE:compile
[INFO] |  \- org.slf4j:jul-to-slf4j:jar:1.7.10:compile
[INFO] +- org.springframework.boot:spring-boot-starter-ws:jar:1.2.2.RELEASE:compile
[INFO] |  +- org.springframework:spring-jms:jar:4.1.5.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-messaging:jar:4.1.5.RELEASE:compile
[INFO] |  +- org.springframework:spring-oxm:jar:4.1.5.RELEASE:compile
[INFO] |  +- org.springframework.ws:spring-ws-core:jar:2.2.0.RELEASE:compile
[INFO] |  \- org.springframework.ws:spring-ws-support:jar:2.2.0.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-data-jpa:jar:1.2.2.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-aop:jar:1.2.2.RELEASE:compile
[INFO] |  |  +- org.aspectj:aspectjrt:jar:1.8.5:compile
[INFO] |  |  \- org.aspectj:aspectjweaver:jar:1.8.5:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-jdbc:jar:1.2.2.RELEASE:compile
[INFO] |  |  \- org.apache.tomcat:tomcat-jdbc:jar:8.0.20:compile
[INFO] |  |     \- org.apache.tomcat:tomcat-juli:jar:8.0.20:compile
[INFO] |  +- javax.transaction:javax.transaction-api:jar:1.2:compile
[INFO] |  +- org.springframework.data:spring-data-jpa:jar:1.7.2.RELEASE:compile
[INFO] |  |  \- org.springframework.data:spring-data-commons:jar:1.9.2.RELEASE:compile
[INFO] |  \- org.springframework:spring-aspects:jar:4.1.5.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-security:jar:1.2.2.RELEASE:compile
[INFO] |  +- org.springframework:spring-expression:jar:4.1.5.RELEASE:compile
[INFO] |  +- org.springframework.security:spring-security-config:jar:3.2.6.RELEASE:compile
[INFO] |  |  +- aopalliance:aopalliance:jar:1.0:compile
[INFO] |  |  \- org.springframework.security:spring-security-core:jar:3.2.6.RELEASE:compile
[INFO] |  +- org.springframework.security:spring-security-web:jar:3.2.6.RELEASE:compile
[INFO] |  \- org.springframework:spring-aop:jar:4.1.5.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-test:jar:1.2.2.RELEASE:test
[INFO] |  +- junit:junit:jar:4.12:test
[INFO] |  +- org.hamcrest:hamcrest-library:jar:1.3:test
[INFO] |  \- org.springframework:spring-test:jar:4.1.5.RELEASE:test
[INFO] +- org.powermock:powermock-reflect:jar:1.6.1:test
[INFO] +- org.powermock:powermock-module-junit4:jar:1.6.1:test
[INFO] |  \- org.powermock:powermock-module-junit4-common:jar:1.6.1:test
[INFO] |     \- org.powermock:powermock-core:jar:1.6.1:test
[INFO] +- org.powermock:powermock-api-mockito:jar:1.6.1:test
[INFO] |  +- org.mockito:mockito-all:jar:1.10.8:test
[INFO] |  \- org.powermock:powermock-api-support:jar:1.6.1:test
[INFO] +- org.mockito:mockito-core:jar:1.10.8:compile
[INFO] |  +- org.hamcrest:hamcrest-core:jar:1.3:runtime
[INFO] |  \- org.objenesis:objenesis:jar:2.1:runtime
[INFO] +- org.hibernate:hibernate-core:jar:4.3.8.Final:compile
[INFO] |  +- org.jboss.logging:jboss-logging:jar:3.1.3.GA:compile
[INFO] |  +- org.jboss.logging:jboss-logging-annotations:jar:1.2.0.Beta1:compile
[INFO] |  +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:jar:1.0.0.Final:compile
[INFO] |  +- dom4j:dom4j:jar:1.6.1:compile
[INFO] |  |  \- xml-apis:xml-apis:jar:1.0.b2:compile
[INFO] |  +- org.hibernate.common:hibernate-commons-annotations:jar:4.0.5.Final:compile
[INFO] |  +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
[INFO] |  +- org.javassist:javassist:jar:3.18.1-GA:compile
[INFO] |  +- antlr:antlr:jar:2.7.7:compile
[INFO] |  \- org.jboss:jandex:jar:1.1.0.Final:compile
[INFO] +- org.hibernate:hibernate-entitymanager:jar:4.3.8.Final:compile
[INFO] +- javax.transaction:jta:jar:1.1:compile
[INFO] +- org.springframework.boot:spring-boot-starter-tomcat:jar:1.2.2.RELEASE:provided
[INFO] |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:8.0.20:provided
[INFO] |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:8.0.20:provided
[INFO] |  +- org.apache.tomcat.embed:tomcat-embed-logging-juli:jar:8.0.20:provided
[INFO] |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.0.20:provided
[INFO] +- org.apache.ws.security:wss4j:jar:1.6.15:compile
[INFO] |  +- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] |  +- org.apache.santuario:xmlsec:jar:1.5.6:compile
[INFO] |  \- org.opensaml:opensaml:jar:2.5.1-1:compile
[INFO] |     \- org.opensaml:openws:jar:1.4.2-1:compile
[INFO] |        \- org.opensaml:xmltooling:jar:1.3.2-1:compile
[INFO] |           \- joda-time:joda-time:jar:2.5:compile (version managed from 1.6.2)
[INFO] +- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.0:compile
[INFO] |  \- org.codehaus.jackson:jackson-core-asl:jar:1.9.0:compile
[INFO] +- org.springframework.ws:spring-ws-security:jar:2.2.0.RELEASE:compile
[INFO] |  +- org.springframework.ws:spring-xml:jar:2.2.0.RELEASE:compile
[INFO] |  \- org.springframework:spring-tx:jar:4.1.5.RELEASE:compile
[INFO] +- com.oracle:ojdbc14:jar:10.2.0.4:compile
[INFO] +- org.apache.httpcomponents:httpclient:jar:4.3.5:compile
[INFO] |  \- org.apache.httpcomponents:httpcore:jar:4.3.2:compile
[INFO] +- org.json:json:jar:20140107:compile
[INFO] +- org.springframework:spring-context-support:jar:4.1.3.RELEASE:compile
[INFO] +- net.sf.ehcache:ehcache:jar:2.9.1:compile
[INFO] \- <redacted>
+4
2

log4j - logging api, slf4j - ab apis

, log4j, slf4j, - ( log4j), , maven maven

slf4j- * ( slfj-api) slf4j-log4j, slf4j log4j log4j.properties, , ,

+2

slf4j log4j.

maven? , pom.xml, slf4j, log4j?

: http://www.mkyong.com/hibernate/how-to-configure-log4j-in-hibernate-project/

log4j 1.2.x maven slf4j log4j appenders:

    <!-- slf4j-log4j -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.6.1</version>
    </dependency>

log4j 2.x maven slf4j log4j appenders:

<dependencies>
  <dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-slf4j-impl</artifactId>
    <version>2.2</version>
  </dependency>
</dependencies>

, !

+2

All Articles