Kamen Jahr
Kamen Jahr

Reputation: 241

Hibernate 4.2:How to trace sql values with JDK logging API

Our current project has no log4j jars, we use JDK logging API only. Now i needed to see the values of HQL statements, which are currently displayed with "?","?".

I found a lot of tips, using LOG4J. But no solution found with JDK:---((

I have set the following in logging.properties:

  1. org.hibernate.level=TRACE
  2. org.hibernate.SQL.level = TRACE
  3. .level=TRACE

But it had no effect. If I set the INFO level, so all WARNs, that I send for tests, will NOT be visible. Thus, logging.properties is bound to Java class path

Does anybody have any ideas?

Upvotes: 1

Views: 2133

Answers (4)

ejaenv
ejaenv

Reputation: 2387

with wireshark you can easily see the full mysql sentences

Upvotes: 0

CSchulz
CSchulz

Reputation: 11020

I have encountered the same issue and doesn't want to use another logging facility.

I ended up with following configuration (original question):

handlers=java.util.logging.ConsoleHandler
java.util.logging.ConsoleHandler.level=FINE
org.hibernate.level=WARN
org.hibernate.SQL.level=FINE

Perhaps not the best one, because it logs sometimes a lot of stuff, but it is working.

Upvotes: 0

lumion
lumion

Reputation: 45

JBoss Logging will look for a System setting with the key org.jboss.logging.provider. What you need to do is to set the system properties with that key with value "jdk", such that Hibernate will use Java logging framework for logging

System.setProperty("org.jboss.logging.provider", "jdk"); 

To log binding parameters in sql, you need one more statement in your logging.properties

org.hibernate.type.descriptor.sql.level=FINEST

You may refer the details from the logging guide of Hibernate http://docs.jboss.org/hibernate/orm/4.3/topical/html/logging/Logging.html

Upvotes: 1

Steve Ebersole
Steve Ebersole

Reputation: 9443

The authoritative resource on Java JDK logging is the Java Logging Guide : http://docs.oracle.com/javase/7/docs/api/java/util/logging/package-summary.html

But generally speaking, JDK logging does not define a TRACE level: http://docs.oracle.com/javase/6/docs/api/java/util/logging/Level.html

Hibernate uses JBoss Logging for its logging. JBoss Logging defines a TRACE level (like most logging libraries other than the JDK); when bridging to JDK logging, JBoss Logging maps TRACE to JDK's FINER level. So you'd want to use =FINER in your config (or =FINEST)

Upvotes: 0

Related Questions