Friday 17 March 2017

How to turning off hibernate logging console output

How to turning off hibernate logging console output

Visit my previous post, Step wise how to implement spring logging with log4j.

My project uses hibernate version 4.3.8 and when implement spring logging with log4j, logger prints all hibernate info on console and file, which I don't want. I want disable hibernate starting info in log or console.

Log4J dependency

//LOG4J
    compile 'log4j:log4j:1.2.17'
    compile 'log4j:apache-log4j-extras:1.2.17'

Hibernate property "hibernate.show_sql" and "hibernate.format_sql" set as false as below but still I was getting hibernate info log in console.

<property name="hibernateProperties">
            <props>
               <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQL82Dialect</prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop>
                <prop key="hibernate.format_sql">false</prop>
                <prop key="hibernate.show_sql">false</prop>
            </props>
</property>


Hibernate info log

INFO    2017-03-17 16:09:07,472 [main] org.hibernate.Version  - HHH000412: Hibernate Core {4.3.8.Final}
INFO    2017-03-17 16:09:07,475 [main] org.hibernate.cfg.Environment  - HHH000206: hibernate.properties not found
INFO    2017-03-17 16:09:07,476 [main] org.hibernate.cfg.Environment  - HHH000021: Bytecode provider name : javassist
INFO    2017-03-17 16:09:09,266 [main] org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory  - HHH000397: Using ASTQueryTranslatorFactory
INFO    2017-03-17 16:09:10,392 [main] org.hibernate.tool.hbm2ddl.SchemaUpdate  - HHH000228: Running hbm2ddl schema update
INFO    2017-03-17 16:09:10,393 [main] org.hibernate.tool.hbm2ddl.SchemaUpdate  - HHH000102: Fetching database metadata
INFO    2017-03-17 16:09:10,405 [main] org.hibernate.tool.hbm2ddl.SchemaUpdate  - HHH000396: Updating schema
INFO    2017-03-17 16:09:10,469 [main] org.hibernate.tool.hbm2ddl.TableMetadata  - HHH000261: Table found: rtp.admi004_msg_tb
INFO    2017-03-17 16:09:10,469 [main] org.hibernate.tool.hbm2ddl.TableMetadata  - HHH000037: Columns: [event_desc, event_id, event_param, event_code, rawmsg_id, event_time]
INFO    2017-03-17 16:09:10,470 [main] org.hibernate.tool.hbm2ddl.TableMetadata  - HHH000108: Foreign keys: []
INFO    2017-03-17 16:09:10,470 [main] org.hibernate.tool.hbm2ddl.TableMetadata  - HHH000126: Indexes: [admi004_msg_tb_pkey]
INFO    2017-03-17 16:09:10,499 [main] org.hibernate.tool.hbm2ddl.TableMetadata  - HHH000261: Table found: rtp.distinct_msg_tb
INFO    2017-03-17 16:09:10,499 [main] org.hibernate.tool.hbm2ddl.TableMetadata  - HHH000037: Columns: [msg_ut_id, resp_rawmsg_id, msg_status, distmsg_id]
INFO    2017-03-17 16:09:10,499 [main] org.hibernate.tool.hbm2ddl.TableMetadata  - HHH000108: Foreign keys: []
INFO    2017-03-17 16:09:10,499 [main] org.hibernate.tool.hbm2ddl.TableMetadata  - HHH000126: Indexes: [distinct_msg_tb_pkey]

Solution : I found one solution to add "log4j.logger.org.hibernate =WARN" in log4j.properties file.

log4j.properties


# LOG4J configuration
log4j.rootLogger=INFO, CONSOLE, FILE

log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%-7p %d [%t] %c %x - %m%n
log4j.logger.org.hibernate =WARN

log4j.appender.FILE=org.apache.log4j.rolling.RollingFileAppender 
log4j.appender.FILE.rollingPolicy=org.apache.log4j.rolling.FixedWindowRollingPolicy 
log4j.appender.FILE.rollingPolicy.maxIndex=2 
log4j.appender.FILE.triggeringPolicy=org.apache.log4j.rolling.SizeBasedTriggeringPolicy 
#log4j.appender.FILE.triggeringPolicy.MaxFileSize=5000000
log4j.appender.FILE.triggeringPolicy.MaxFileSize=50000
log4j.appender.FILE.rollingPolicy.FileNamePattern=D:/Error-%i.log 
log4j.appender.FILE.rollingPolicy.ActiveFileName=D:/Error.log
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout 
log4j.appender.FILE.layout.ConversionPattern=%d %-5p - %c %x %m%n


Related Post:



Stepwise how to implement spring logging with log4j

How can I disable application context info in log or console

1 comment: