-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Disable Console Logging
PostPosted: Sat Jun 06, 2015 10:10 am 
Newbie

Joined: Sat Jun 06, 2015 9:42 am
Posts: 1
I have searched on the Internet but I could not find how to disable hibernate 'INFO' messages on the console. Searched over websites like stackoverflow and many solutions focus on the hibernate configuration file. I have edited accordingly.

Code:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration SYSTEM
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
   <session-factory>
      <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
      <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
      <property name="hibernate.connection.url">jdbc:postgresql://localhost/hiberdatabase</property>
      <property name="hibernate.connection.username">hiberuser</property>
      <property name="hibernate.connection.password">test</property>
      <property name="hibernate.hbm2ddl.auto">update</property>
      <property name="hibernate.show_sql">false</property>

      <mapping class="Employee" />
   </session-factory>
</hibernate-configuration>


I am able to read this file properly.
I have also tried to change this property programmatically. You can find the code below:
Code:
      File configFile = new File("src/resources/hibernate.cfg.xml");
      Configuration configuration = new Configuration();
      configuration.configure(configFile);
      configuration.setProperty("hibernate.show_sql", "false");


So far, still no change. I do not know what to do. Can someone assist me?

EDIT:
Ok. I found a solution worked for me. You can access it through the link:
http://stackoverflow.com/a/18323888/1454756


Top
 Profile  
 
 Post subject: Re: Disable Console Logging
PostPosted: Wed Jun 17, 2015 2:35 am 
Newbie

Joined: Mon Apr 30, 2012 2:19 am
Posts: 6
Hibernate is using SLF4J I think to send all log messages. So you can configure any SLF4J compatible logging framework.

For example, what I often do is adding logback to my dependencies (I'm using maven) :

Code:
<dependency>
   <groupId>ch.qos.logback</groupId>
   <artifactId>logback-classic</artifactId>
   <version>1.1.3</version>
</dependency>


If you are as lazy as I am you can also add binding that redirect log4j to SLF4J (logback) in case any other library is using log4j :
Code:
<dependency>
   <groupId>org.slf4j</groupId>
   <artifactId>log4j-over-slf4j</artifactId>
   <version>1.7.7</version>
</dependency>

Then I also add a binding to redirect java.util.logging to SLF4J:
Code:
<dependency>
   <groupId>org.slf4j</groupId>
   <artifactId>jul-to-slf4j</artifactId>
   <version>1.7.7</version>
</dependency>

And also one that redirect Apache Commons Logging to SLF4J :
Code:
<dependency>
   <groupId>org.slf4j</groupId>
   <artifactId>jcl-over-slf4j</artifactId>
   <version>1.7.7</version>
</dependency>


Those 3 other dependencies are not required but with this I'm sure that I can configure only logback and all other log will be redirected to it.

To configure logback check the logback documentation : http://logback.qos.ch/manual/configuration.html
But here's my sample logback.xml (to place at the root of the classpath : ${basedir}/src/main/resource) where I send everything to the STDOUT with a default level of TRACE and filter out packages I doon't want to see with WARN level:
Code:
<configuration>
   <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
      <encoder>
         <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
      </encoder>
   </appender>

   <logger name="demo01" level="trace" />
   
   <logger name="org.hibernate" level="warn" />
   <logger name="org.hibernate.SQL" level="debug" />
   <logger name="org.hibernate.type.descriptor.sql.BasicBinder" level="warn" />
   <logger name="org.hibernate.type.BasicTypeRegistry" level="warn" />
   <logger name="net.sf.ehcache" level="warn" />
   <logger name="org.jboss" level="warn" />

   <root level="trace">
      <appender-ref ref="STDOUT" />
   </root>
</configuration>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.