我最近添加了休眠到我的pom.xml,它工作正常。然而,日誌記錄是令人煩惱的,我不知道如何關閉它或限制它的級別(我甚至不知道它包含了什麼以啓動所有這些日誌記錄)。我對此很陌生,希望能夠熟練和冬眠。從maven中禁用與休眠日誌記錄
這裏是我的pom.xml依賴:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Hibernate -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.common</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>4.0.1.Final</version>
<classifier>tests</classifier>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.10</version>
</dependency>
</dependencies>
日誌開始是這樣的:
21:17:15.115 [main] DEBUG org.jboss.logging - Logging Provider: org.jboss.logging.Slf4jLoggerProvider
21:17:15.130 [main] DEBUG org.hibernate.type.BasicTypeRegistry - Adding type registration boolean -> [email protected]
21:17:15.130 [main] DEBUG org.hibernate.type.BasicTypeRegistry - Adding type registration boolean -> [email protected]
21:17:15.130 [main] DEBUG org.hibernate.type.BasicTypeRegistry - Adding type registration java.lang.Boolean -> [email protected]
我曾嘗試加入log4j.properties文件到我的資源,它似乎沒有改變任何事情。我也嘗試了simplelog.properties(下面的其他SO帖子沒有幫助)。我有點卡在這裏,幫助將非常感激。理想情況下,我想只設置記錄器關閉,或只是MySQL查詢。
這是依賴關係樹:
[INFO] org.springframework:gs-rest-service:jar:0.1.0
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:1.1.10.RELEASE:compile
[INFO] | +- org.springframework.boot:spring-boot-starter:jar:1.1.10.RELEASE:compile
[INFO] | | +- org.springframework.boot:spring-boot:jar:1.1.10.RELEASE:compile
[INFO] | | +- org.springframework.boot:spring-boot-autoconfigure:jar:1.1.10.RELEASE:compile
[INFO] | | +- org.springframework.boot:spring-boot-starter-logging:jar:1.1.10.RELEASE:compile
[INFO] | | | +- org.slf4j:jcl-over-slf4j:jar:1.7.7:compile
[INFO] | | | | \- org.slf4j:slf4j-api:jar:1.7.7:compile
[INFO] | | | +- org.slf4j:jul-to-slf4j:jar:1.7.7:compile
[INFO] | | | +- org.slf4j:log4j-over-slf4j:jar:1.7.7:compile
[INFO] | | | \- ch.qos.logback:logback-classic:jar:1.1.2:compile
[INFO] | | | \- ch.qos.logback:logback-core:jar:1.1.2:compile
[INFO] | | \- org.yaml:snakeyaml:jar:1.13:runtime
[INFO] | +- org.springframework.boot:spring-boot-starter-tomcat:jar:1.1.10.RELEASE:compile
[INFO] | | +- org.apache.tomcat.embed:tomcat-embed-core:jar:7.0.57:compile
[INFO] | | +- org.apache.tomcat.embed:tomcat-embed-el:jar:7.0.57:compile
[INFO] | | +- org.apache.tomcat.embed:tomcat-embed-logging-juli:jar:7.0.57:compile
[INFO] | | \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:7.0.57:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-databind:jar:2.3.4:compile
[INFO] | | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.3.4:compile
[INFO] | | \- com.fasterxml.jackson.core:jackson-core:jar:2.3.4:compile
[INFO] | +- org.hibernate:hibernate-validator:jar:5.0.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.0.8.RELEASE:compile
[INFO] | +- org.springframework:spring-web:jar:4.0.8.RELEASE:compile
[INFO] | | +- org.springframework:spring-aop:jar:4.0.8.RELEASE:compile
[INFO] | | | \- aopalliance:aopalliance:jar:1.0:compile
[INFO] | | +- org.springframework:spring-beans:jar:4.0.8.RELEASE:compile
[INFO] | | \- org.springframework:spring-context:jar:4.0.8.RELEASE:compile
[INFO] | \- org.springframework:spring-webmvc:jar:4.0.8.RELEASE:compile
[INFO] | \- org.springframework:spring-expression:jar:4.0.8.RELEASE:compile
[INFO] +- org.hibernate:hibernate-core:jar:4.0.1.Final:compile
[INFO] | +- commons-collections:commons-collections:jar:3.2.1:compile
[INFO] | +- antlr:antlr:jar:2.7.7:compile
[INFO] | +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.1_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.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.1.Final:compile
[INFO] | +- org.jboss.logging:jboss-logging:jar:3.1.0.CR2:compile
[INFO] | +- org.javassist:javassist:jar:3.18.1-GA:compile
[INFO] | \- org.hibernate.common:hibernate-commons-annotations:jar:4.0.1.Final:compile
[INFO] +- org.hibernate.common:hibernate-commons-annotations:jar:tests:4.0.1.Final:compile
[INFO] \- mysql:mysql-connector-java:jar:5.1.10:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 35.918 s
[INFO] Finished at: 2015-02-07T22:09:37+00:00
[INFO] Final Memory: 20M/203M
[INFO] ------------------------------------------------------------------------
解決方案是添加在該項目的資源文件夾命名爲「logback.xml」的配置文件。這個文件的內容是:
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
</configuration>
感謝您發佈您的解決方案。它幫助了我。 – Bhushan 2015-05-27 10:06:40