日期:2014-05-20  浏览次数:20849 次

log4j如何配置hibernate输出的信息打印到文件中
hibernante输出的hql语句:  
  Hibernate: select regiondef0_.REGION_ID as REGION1_1_, regiondef0_.NAME as NAME1_, regiondef0_.REGION_TYPE as REGION3_1_, regiondef0_.HOME_ID as HOME4_1_ from REGION_DEF regiondef0_ where regiondef0_.REGION_ID<1000 and regiondef0_.HOME_ID=0  
  Hibernate: select regiondef0_.REGION_ID as REGION1_1_, regiondef0_.NAME as NAME1_, regiondef0_.REGION_TYPE as REGION3_1_, regiondef0_.HOME_ID as HOME4_1_ from REGION_DEF regiondef0_ where regiondef0_.REGION_ID<1000 and regiondef0_.HOME_ID=0  
  不能打印到指定的文件中????  
 ### direct log messages to stdout ###  
  log4j.rootLogger=info,stdout,hfile  
   
  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{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n  
   
  ### direct messages to file hibernate.log ###  
  ### 输出到日志文件 ###  
  log4j.appender.hfile = org.apache.log4j.DailyRollingFileAppender  
  log4j.appender.hfile.File = ../log_bias.log  
  log4j.appender.hfile.layout = org.apache.log4j.PatternLayout  
  log4j.appender.hfile.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n  
   
  ### set log levels - for more verbose logging change 'info' to 'debug' ###  
   
   
   
  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=info  
   
  ### log JDBC bind parameters ###  
  log4j.logger.org.hibernate.type=info  
  #log4j.logger.org.hibernate.type=debug  
   
  ### log schema export/update ###  
  log4j.logger.org.hibernate.tool.hbm2ddl=debug  
   
  ### log HQL parse trees  
  log4j.logger.org.hibernate.hql=info  
   
  ### 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  


------解决方案--------------------