我有一個春季啓動Web應用程序。嘗試自定義日誌記錄。我瞭解slf4j和log4j之間的區別。在這種情況下我需要使用log4j。大多數情況下,它的工作方式是我想要的。春季啓動Web應用程序:獲取休眠以使用log4j
問題是,Hibernate將SQL查詢打印到控制檯,並基於格式,我認爲它根本不使用log4j。我想進一步定製Hibernate正在記錄的內容。我看到的大部分建議都假設Hibernate正在通過log4j進行日誌記錄。我怎麼會得到休眠使用log4j作爲其日誌框架?
我試着排除jboss日誌記錄,然後我知道jboss實際上是一個類似於slf4j的外觀排序,所以排除它似乎不能解決問題(並且當我對它有特別的侵略性時,應用程序無法啓動)
我還不知道如何配置jboss或hibernate。我對此很感興趣,所以如果您對如何實施建議的解決方案有合理的詳細說明,我將不勝感激。
更新: 有人問,是的,我使用的是Maven。 我遵循Spring Boot頁面的指導,以排除logback,以便spring引導改爲使用log4j。我確定現在絕大多數應用程序都使用log4j進行日誌記錄 - 無論是直接還是通過slf4j - 因爲系統正在按照我的log4j配置文件指示進行操作。
無論應用程序是直接使用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>