• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Hibernate 3 -> Logging queries to file with log4j

 
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

 
Bartender
Posts: 10336
Hibernate Eclipse IDE 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.
 
Every plan is a little cooler if you have a blimp. And a tiny ad.
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic