• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate 3 -> Logging queries to file with log4j

 
Santosh Ramachandrula
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to log the sql queries to a file but it is not. I have log messages at debug level in Java Code. (What am I missing?)

This is my log4j.properties setting




In the console I see



Contents of hibernate.log file

 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I am trying to log the sql queries to a file but it is not. I have log messages at debug level in Java Code. (What am I missing?)

If you use the Hibernate properties hibernate.show_sql and hibernate.format_sql Hibernate will log at INFO to any appender configured with that threshold.
 
Santosh Ramachandrula
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul, This is my understanding from what you said " if hibernate.show_sql and hibernate.format_sql are configured in hibernate.cfg.xml then I will have to use a threshold level of INFO in order to log the sql statements to log file" Is that right?

I pulled the log4j.properties bundled with the hibernate project into my project for this(pleae see below) but I have been unsuccessful. Can you please highlight the changes in the configuration below that I need to make in order to achieve logging sql queries to log file it would be great.

--------------log4j.properties-----------------



-------------hibernate.cfg.xml setting-------------
 
Santosh Ramachandrula
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Copied the hibernate.cfg.xml and log4j.properties to test hibernate project and it worked. Something else is the culprit.
 
Santosh Ramachandrula
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It works now. Was missing slf4j-log4j12-1.5.6.jar in my application lib.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic