问题描述
我有如下所示的crearte log4j.properties 文件:
log4j.logger.org。 hibernate = INFO,hb
log4j.logger.org.hibernate.SQL = DEBUG
log4j.logger.org.hibernate.type = TRACE
log4j.logger.org.hibernate.hql.ast .AST = info
log4j.logger.org.hibernate.tool.hbm2ddl = warn
log4j.logger.org.hibernate.hql = debug
log4j.logger.org.hibernate.cache = info
log4j.logger.org.hibernate.jdbc = debug
log4j.appender.hb = org.apache.log4j.ConsoleAppender
log4j.appender.hb.layout = org .apache.log4j.PatternLayout
log4j.appender.hb.layout.ConversionPattern = HibernateLog - > %d {HH:mm:ss}%-5p%c - %m%n
log4j.appender.hb.Threshold = TRACE
有人可以帮助我如何将它包含在 hibernate.cfg.xml 文件中?我很抱歉,我实际上不知道log4j是如何工作的。我使用 value 而不是?来创建这个来显示我的hibernate查询,但它仍然显示? 没有任何变化,所以我需要进一步处理?
我从这里参考
hibernate.cfg.xml中的属性会将查询直接打印到控制台。Log4j允许输出记录到从控制台到文件到网络端口到数据库的任何地方。
但是,您拥有的简单配置也应该在控制台上打印。因此,首先删除show_sql属性,以查看Log4j是否在控制台上放置任何东西。
如果这不起作用,则表示Log4j配置不正确。如果你使用的是hibernate> 3.5,它使用slf4j api,默认情况下使用logback而不是log4j。
您可以通过从类路径中删除logback jar来轻松地切换到log4j,并添加slf4j-log4j12.jar和log4j.jar。
Log4j跟踪也使用'?'打印查询,但它也打印参数绑定,即'?'将被数据库驱动程序或服务器替换。
I have crearte log4j.properties file like below:
log4j.logger.org.hibernate=INFO, hb log4j.logger.org.hibernate.SQL=DEBUG log4j.logger.org.hibernate.type=TRACE log4j.logger.org.hibernate.hql.ast.AST=info log4j.logger.org.hibernate.tool.hbm2ddl=warn log4j.logger.org.hibernate.hql=debug log4j.logger.org.hibernate.cache=info log4j.logger.org.hibernate.jdbc=debug log4j.appender.hb=org.apache.log4j.ConsoleAppender log4j.appender.hb.layout=org.apache.log4j.PatternLayout log4j.appender.hb.layout.ConversionPattern=HibernateLog --> %d{HH:mm:ss} %-5p %c - %m%n log4j.appender.hb.Threshold=TRACE
Can someone help me to how to include it in hibernate.cfg.xml file? I am sorry I actually don't know how log4j works. I create this to display my hibernate query with value instead of ? but still it displays ? nothing changes so what I need to proceed further?
I took reference from here Hibernate show real SQL
The 'show_sql' property in your hibernate.cfg.xml causes the queries to be printed directly to the console.
Log4j allows output to be logged anywhere from console to file to network ports to databases.But the simple configuration that you have is supposed to print on the console as well. So first remove the show_sql property to see if Log4j puts anything on the console at all.
If this doesn't work, it shows that Log4j is not configured correctly. If you're using hibernate > 3.5, it uses the slf4j api, which uses logback by default instead of log4j.You can easily switch to log4j by removing logback jar(s) from your classpath, and adding slf4j-log4j12.jar and log4j.jar instead.
The Log4j tracing also prints the queries using '?', but it also prints the parameter bindings, i.e. what the '?' will be replaced with by the database driver or server.
这篇关于在hibernate中包含log4j属性文件以显示带有值而不是问号的查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!