如何在Eclipse中禁用休眠日志?(How to disable Hibernate logs i

2019-10-22 17:30发布

我是新来冬眠,我在Eclipse中做项目。 当我登录到我的应用程序会显示在控制台中,我不需要很多日志消息,日志消息是这样的,

97 [http-bio-8080-exec-9] INFO org.hibernate.annotations.common.Version - Hibernate Commons Annotations 3.2.0.Final
102 [http-bio-8080-exec-9] INFO org.hibernate.cfg.Environment - Hibernate 3.6.10.Final
103 [http-bio-8080-exec-9] INFO org.hibernate.cfg.Environment - hibernate.properties not found
105 [http-bio-8080-exec-9] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
108 [http-bio-8080-exec-9] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
165 [http-bio-8080-exec-9] INFO org.hibernate.cfg.Configuration - configuring from resource: /hibernate.cfg.xml
165 [http-bio-8080-exec-9] INFO org.hibernate.cfg.Configuration - Configuration resource: /hibernate.cfg.xml
220 [http-bio-8080-exec-9] INFO org.hibernate.cfg.Configuration - Configured SessionFactory: null
262 [http-bio-8080-exec-9] INFO org.hibernate.cfg.AnnotationBinder - Binding entity from annotated class: com.aurodisplay.its.beans.UserRegisterBean
296 [http-bio-8080-exec-9] INFO org.hibernate.cfg.annotations.EntityBinder - Bind entity com.aurodisplay.its.beans.UserRegisterBean on table users
334 [http-bio-8080-exec-9] INFO org.hibernate.cfg.AnnotationBinder - Binding entity from annotated class: com.aurodisplay.its.beans.AdminInfoBean
334 [http-bio-8080-exec-9] INFO org.hibernate.cfg.annotations.EntityBinder - Bind entity com.aurodisplay.its.beans.AdminInfoBean on table admin_info
337 [http-bio-8080-exec-9] INFO org.hibernate.cfg.AnnotationBinder - Binding entity from annotated class: com.aurodisplay.its.beans.LatitudeBean
337 [http-bio-8080-exec-9] INFO org.hibernate.cfg.annotations.EntityBinder - Bind entity com.aurodisplay.its.beans.LatitudeBean on table latlng

我的hibernate.cfg.xml

<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
    "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<session-factory>

    <!-- Database connection settings -->
    <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="connection.url">jdbc:mysql://localhost:3306/its_serverdb</property>
    <property name="connection.username">root</property>
    <property name="connection.password">root</property>

    <!-- JDBC connection pool (use the built-in) -->
    <property name="connection.pool_size">10</property>

    <!-- SQL dialect -->
    <property name="dialect">org.hibernate.dialect.MySQLDialect</property>

    <!-- Disable the second-level cache  -->
    <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

    <!-- Echo all executed SQL to stdout -->
    <property name="show_sql">true</property>

    <property name="hibernate.connection.zeroDateTimeBehavior">convertToNull</property>
  <property name="hibernate.connection.release_mode">on_close</property>
     // next are mappings

我已经集成Log4j的,这是我的log4j.xml文件

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration debug="true" xmlns:log4j='http://jakarta.apache.org/log4j/'>

<appender name="console" class="org.apache.log4j.ConsoleAppender">
    <layout class="org.apache.log4j.PatternLayout">
    <param name="ConversionPattern" value="[%d{dd-MM-yyyy HH:mm:ss}] [%c{1}] %-5p :%L - %m%n" />
    </layout>
</appender>

<appender name="file" class="org.apache.log4j.RollingFileAppender">
    <param name="append" value="false" />
    <param name="maxFileSize" value="10MB" />
    <param name="maxBackupIndex" value="10" />
    <param name="file" value="${catalina.home}/logs/ITS_Server.log" />
    <layout class="org.apache.log4j.PatternLayout">
    <param name="ConversionPattern" value="[%d{dd-MM-yyyy HH:mm:ss}] [%c{1}] %-5p:%L - %m%n" />
    </layout>
</appender>

<category name="org.hibernate">
    <priority value="DEBUG" />
</category>

<category name="java.sql">
    <priority value="debug" />
</category>

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

<root>
    <level value="DEBUG" />
    <appender-ref ref="console" />
    <appender-ref ref="file" />


  </root>

 </log4j:configuration>

我如何可以禁用它。 当我google一下吧,somany解决方案是使用Log4j我不知道它是什么,什么是它。 我该怎么办没有禁用日志Log4j如果可能的话,请告诉我。它怎么会是马丽娟帮助。 谢谢。

Answer 1:

<property name="show_sql">false</property>

当创建会话使用

Logger log = Logger.getLogger("org.hibernate");
    log.setLevel(Level.your_level); 

这应该停止记录,你不必使用任何xmlcfg文件



Answer 2:

尝试在的log4j.xml follwing线。

<Root> 
<Level value = "INFO" /> 
<Appender-ref ref = "console" /> 
<Appender-ref ref = "rootLogger" /> 
</Root>

我用下面一行在为我工作log4j.properties。

log4j.rootLogger=DEBUG, file, console
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=../logs/Log_report.log
log4j.appender.file.MaxFileSize=1MB
log4j.appender.file.MaxBackupIndex=1
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n


Answer 3:

尝试设置

log4j.logger.org.hibernate=info

更多信息关闭Hibernate日志控制台输出



Answer 4:

由于你没有任何记录器,尝试在添加此hibernate.cfg.xml文件

<!-- Limit the org.hibernate category to INFO since logging to DEBUG affects performance badly -->  
<category name="org.hibernate">  
    <priority value="WARN"/>  
</category>  

O写你的日志信息到一个文件,当你有Log4j的安装,你将不得不使用org.apache.log4j.FileAppender。

下面是FileAppender一个示例配置文件log4j.properties -

# Define the root logger with appender file
log4j.rootLogger = DEBUG, FILE

# Define the file appender
log4j.appender.FILE=org.apache.log4j.FileAppender

# Set the name of the file
log4j.appender.FILE.File=${log}/log.out

# Set the immediate flush to true (default)
log4j.appender.FILE.ImmediateFlush=true

# Set the threshold to debug mode
log4j.appender.FILE.Threshold=debug

# Set the append to false, overwrite
log4j.appender.FILE.Append=false

# Define the layout for file appender
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.conversionPattern=%m%n

请在这里和这里的进一步信息。



Answer 5:

旧的职位,但有用:

首先,你可以使用log4j的配置文件(添加到您的pom.xml)

<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.17</version>
</dependency>

最后,如果要禁用记录,投入的src /主/资源/ log4j.properties文件

log4j.rootLogger=OFF


文章来源: How to disable Hibernate logs in Eclipse?