日期:2014-05-17  浏览次数:20740 次

hibernate 的log4j怎么写 才能输出sql语句 ?? 在线等
这是我的log4j文件
--------
#log4j.rootLogger=DEBUG, stdout,logfile,INFO
log4j.rootLogger=DEBUG,stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n

log4j.logger.java.sql.PreparedStatement=DEBUG

log4j.appender.logfile=org.apache.log4j.RollingFileAppender
log4j.appender.logfile.File=${czqs.root}/WEB-INF/czqs.log
log4j.appender.logfile.MaxFileSize=1024KB
# Keep three backup files.
log4j.appender.logfile.MaxBackupIndex=3
# Pattern to output: date priority [category] - message
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern=%d %p [%c] - %m%n
----------

怎样才能使他输出sql语句 
怎样才能使他的输出少一点 感觉太多无用信息或我不想了解的信息 影响我观看  

这是我的log4j输出
2011-11-02 23:44:53,921 DEBUG [com.opensymphony.xwork2.conversion.impl.XWorkConverter] - Class: ssh2.wq.fn.entity.Question
2011-11-02 23:44:53,921 DEBUG [com.opensymphony.xwork2.conversion.impl.XWorkConverter] - field-level type converter for property [qawnum] = none found
2011-11-02 23:44:53,921 DEBUG [com.opensymphony.xwork2.conversion.impl.XWorkConverter] - Property: qawnum.qawnum
2011-11-02 23:44:53,921 DEBUG [com.opensymphony.xwork2.conversion.impl.XWorkConverter] - Class: ssh2.wq.fn.entity.Question
2011-11-02 23:44:53,921 DEBUG [com.opensymphony.xwork2.conversion.impl.XWorkConverter] - global-level type converter for property [qawnum] = none found
2011-11-02 23:44:53,921 DEBUG [com.opensymphony.xwork2.conversion.impl.XWorkConverter] - falling back to default type converter [com.opensymphony.xwork2.conversion.impl.XWorkBasicConverter@1064b80]
2011-11-02 23:44:53,921 DEBUG [com.opensymphony.xwork2.conversion.impl.XWorkConverter] - Property: qsid
2011-11-02 23:44:53,921 DEBUG [com.opensymphony.xwork2.conversion.impl.XWorkConverter] - Class: ssh2.wq.fn.entity.Question
2011-11-02 23:44:53,921 DEBUG [com.opensymphony.xwork2.conversion.impl.XWorkConverter] - field-level type converter for property [qsid] = none found
2011-11-02 23:44:53,921 DEBUG [com.opensymphony.xwork2.conversion.impl.XWorkConverter] - Property: qsid.qsid
2011-11-02 23:44:53,921 DEBUG [com.opensymphony.xwork2.conversion.impl.XWorkConverter] - Class: ssh2.wq.fn.entity.Question


------解决方案--------------------
这个是在hibernate配置文件中配置的
Java code
<property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">
                    org.hibernate.dialect.MySQL5Dialect
                </prop>
                <prop key="hibernate.show_sql">
                    true
                </prop>
                <prop key="hibernate.format_sql">
                    true
                </prop>
            </props>
        </property>

------解决方案--------------------
#log4j.rootLogger=debug, stdout
log4j.logger.net.sf.hibernate=warn

### log just the SQL
log4j.logger.net.sf.hibernate.SQL=debug

### log JDBC bind parameters ###
log4j.logger.net.sf.hibernate.type=info

### log schema export/update ###
log4j.logger.net.sf.hibernate.tool.hbm2ddl=debug

### log cache activity ###
#log4j.logger.net.sf.hibernate.cache=debug

xml中:
<property name="hibernateProperties">
<props>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.format_sql">true</prop>
<!-- <prop key="hibernate.query.factory_class">org.hibernate.