gpt4 book ai didi

java - 从 maven 禁用 hibernate 日志记录

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:36:00 25 4
gpt4 key购买 nike

我最近在我的 pom.xml 中添加了 hibernate,它运行良好。但是,日志记录很烦人,我不确定如何关闭它或限制它的级别(我什至不知道它包含什么来启动所有这些日志记录)。我对此很陌生,对 maven 和 hibernate 都是陌生的。

这是我的 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 -> org.hibernate.type.BooleanType@ba4d54
21:17:15.130 [main] DEBUG org.hibernate.type.BasicTypeRegistry - Adding type registration boolean -> org.hibernate.type.BooleanType@ba4d54
21:17:15.130 [main] DEBUG org.hibernate.type.BasicTypeRegistry - Adding type registration java.lang.Boolean -> org.hibernate.type.BooleanType@ba4d54

我已经尝试将 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>

最佳答案

您可能在日志框架配置中设置了全局 DEBUG 日志级别。

您需要做的就是将 org.hibernate 日志级别设置为 WARNERROR:

  • Logback/Log4j2

    <logger name="org.hibernate" level="warn"/>
  • Log4j

    <logger name="org.hibernate">
    <level value="warn"/>
    </logger>

关于java - 从 maven 禁用 hibernate 日志记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28387553/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com