Hibernate配置Log4J,很有参考价值的

hibernate3 自带的默认的日志框架是slf4j,hibernate3的slf只是一个日志的接口,而hibernate3 自带默认的日志框架,在实际开发中很少有公司或者是项目中用到,这里记录一种使用log4j的日志框架来代替slf4j日志框架的实现,具体配置以及实现如下:

一.加入log4j的日志框架

Hibernate配置Log4J,很有参考价值的

说明:1.    slf4j-api-1.6.1.jar文件,就是前面指的hibernate3自带日志的API(提供了各种日志的接口).

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

3.    slf4j-log4j12-1.6.1.jar文件,就是hibernate3自带的日志接口与log4j中间进行转换的适配器。

 

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

  

你可能感兴趣的:(Hibernate)