I am new to hibernate , I am doing project in Eclipse. When I log in to my application it displays to many log messages in console which I dont need, the log message is something like this,
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
My 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
I have integrated Log4j , Here is my Log4j.xml file
<?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>
How can I disable it. When I google about it, somany solutions are using Log4j
I dont know what is it and what is it for. can I do disable logs without Log4j
if possible please tell me how .It would be greate help. Thank you.
As you dont have any logger, try adding this in your
hibernate.cfg.xml
fileo write your logging information into a file, when you have Log4j installed you would have to use org.apache.log4j.FileAppender.
Following is a sample configuration file log4j.properties for FileAppender −
Check here and here for further info.
Try to set
log4j.logger.org.hibernate=info
More info Turning off hibernate logging console output
Try follwing lines in log4j.xml.
I used following line in log4j.properties which worked for me.
set
When creating session use
This should stop the logging and you don't have to use any
xml
orcfg
fileOld post, but usefull :
First, you can use log4j configuration file (add this to your pom.xml)
Finally, to disable logging, put in src/main/resources/log4j.properties file