小编典典

禁用从Maven休眠的日志记录

hibernate

我最近将hibernate状态添加到了pom.xml中,并且运行良好。但是,日志记录很烦人,我不确定如何关闭它或限制它的级别(我什至不知道启动所有这些日志记录都包括了什么)。我是新来的,行尸走肉和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>

阅读 293

收藏
2020-06-20

共1个答案

小编典典

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

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

  • 登录/ Log4j2
        <logger name="org.hibernate" level="warn"/>
  • Log4j
        <logger name="org.hibernate">
       <level value="warn"/> 
    </logger>
2020-06-20