Prerna
Prerna

Reputation: 111

How to disable hibernate logging in console?

I am trying to disable hibernate logging in my console , i tried the below. The below code belongs to my app-config.xml:-

<bean id="sessionFactory" name="sourceFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
    <property name="dataSource" ref="myprojds"/>
    <property name="packagesToScan" value="com.myproj" />
    <property name="hibernateProperties">
        <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
                <prop key="hibernate.cglib.use_reflection_optimizer">false</prop>
                <prop key="hibernate.jdbc.batch_size">50</prop>
                <prop key="hibernate.default_batch_fetch_size">50</prop>
                <prop key="hibernate.show_sql">false</prop>
                <prop key="hibernate.use_sql_comments">false</prop>
                <prop key="hibernate.generate_statistics">false</prop>
                <prop key="hibernate.format_sql">false</prop>
                <prop key="hibernate.hbm2ddl.auto">false</prop>
                <prop key="hibernate.enable_lazy_load_no_trans">true</prop>
            </props>
    </property>
</bean> 

The below code belongs to log4j.xml:-

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">

<appender name="appender1" class="org.apache.log4j.RollingFileAppender">
    <param name="file" value="/opt/info_${current.date}.log"/>
    <param name="append" value="false"/>
    <param name="maxFileSize" value="2MB"/>
    <param name="maxBackupIndex" value="200"/>
    <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern" value="%d [%t] %5p (%F:%M:%L) - %m%n" />
    </layout>
</appender>
<root>
    <priority value ="error" />
    <appender-ref ref="appender1"/>
</root>
<logger name="org.hibernate"  additivity="false">
    <appender-ref ref="appender1"/> 
    <level value="error" /> 
</logger>

 </log4j:configuration> 

I am still not sure why i am seeing hibernate logs in the console. Please help

Upvotes: 0

Views: 1914

Answers (2)

Vitor Santos
Vitor Santos

Reputation: 611

In newer hibernate version the logging is done by using JBoss Logging as a bridge between many logger implementations. This thread has a discussion on how to set slf4j in hibernate 4, but the problem is pretty similar. You may have to debug this class to check how hibernate is selecting it's logging provider. Maybe you are having a classpath problem (hibernate is not finding the log4j in classpath). There is chance that you'll have to set some system property or create a service loader file (the first link has some hints on this) for hibernate to select the logging provider correctly.

Upvotes: 1

Cacho Casta&#241;a
Cacho Casta&#241;a

Reputation: 21

That is the configuration for a RollingFileAppender (log to files at /opt/info_${current.date}.log, not the console). See if there is a ConsoleAppender somewhere in your config. If there is no ConsoleAppender then you might be seeing console logs from system.out within the code itself.

Upvotes: 0

Related Questions