Hibernate配置Log4J,頗有參考價值的

hibernate3 自帶的默認的日誌框架是slf4j,hibernate3的slf只是一個日誌的接口,而hibernate3 自帶默認的日誌框架,在實際開發中不多有公司或者是項目中用到,這裏記錄一種使用log4j的日誌框架來代替slf4j日誌框架的實現,具體配置以及實現以下:html

一.加入log4j的日誌框架sql

說明:1.    slf4j-api-1.6.1.jar文件,就是前面指的hibernate3自帶日誌的API(提供了各類日誌的接口).apache

2.    log4j-1.2.16.jar文件,就是log4j的框架.api

3.    slf4j-log4j12-1.6.1.jar文件,就是hibernate3自帶的日誌接口與log4j中間進行轉換的適配器。app

 

log4j.properties 參考配置框架

### direct log messages to stdout ###  
log4j.appender.stdout=org.apache.log4j.ConsoleAppender  
log4j.appender.stdout.Target=System.out  
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout  
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n  
  
### direct messages to file hibernate.log ###  
#log4j.appender.file=org.apache.log4j.FileAppender  
#log4j.appender.file.File=hibernate.log  
#log4j.appender.file.layout=org.apache.log4j.PatternLayout  
#log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n  
  
### set log levels - for more verbose logging change 'info' to 'debug' ###  
  
log4j.rootLogger=warn, stdout  
  
#log4j.logger.org.hibernate=info  
#log4j.logger.org.hibernate=debug  
  
### log HQL query parser activity  
#log4j.logger.org.hibernate.hql.ast.AST=debug  
  
### log just the SQL  
#log4j.logger.org.hibernate.SQL=debug  
  
### log JDBC bind parameters ###  
#log4j.logger.org.hibernate.type=info  
#log4j.logger.org.hibernate.type=debug  
log4j.logger.org.hibernate.type.descriptor.sql.BasicBinder=TRACE  
  
### log schema export/update ###  
log4j.logger.org.hibernate.tool.hbm2ddl=debug  
  
### log HQL parse trees  
#log4j.logger.org.hibernate.hql=debug  
  
### log cache activity ###  
#log4j.logger.org.hibernate.cache=debug  
  
### log transaction activity  
#log4j.logger.org.hibernate.transaction=debug  
  
### log JDBC resource acquisition  
#log4j.logger.org.hibernate.jdbc=debug  
  
### enable the following line if you want to track down connection ###  
### leakages when using DriverManagerConnectionProvider ###  
#log4j.logger.org.hibernate.connection.DriverManagerConnectionProvider=trace
相關文章
相關標籤/搜索