java 在 jBoss 日志中显示/隐藏 SQL 查询

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27985924/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 12:45:35  来源:igfitidea点击:

Show / Hide SQL queries in jBoss Logs

javahibernatejboss7.x

提问by Sagar Koshti

I know we can hide / show sql queries from hibernate.cfg.xmlor persistence.xmlwith following code:

我知道我们可以隐藏/显示从SQL查询hibernate.cfg.xmlpersistence.xml与下面的代码:

<property name="show_sql">true</property>

but is there any way to do same from jBoss configuration files?

但是有没有办法从 jBoss 配置文件中做同样的事情?

回答by Poornan

in Jboss EAP 6.2.

在 Jboss EAP 6.2 中。

Need to set environment variable by changing standalone.xml

需要通过更改 standalone.xml 来设置环境变量

<system-properties>
  <property name="org.jboss.as.logging.per-deployment" value="false"/>
</system-properties>

Alternately, you can give it as a JVM option.

或者,您可以将其作为 JVM 选项提供。

$ standalone.sh -Dorg.jboss.as.logging.per-deployment=false

Then in standalone.xml add the following under <subsystem xmlns="urn:jboss:domain:logging:1.3">element

然后在 standalone.xml<subsystem xmlns="urn:jboss:domain:logging:1.3">元素下添加以下内容

<logger category="org.hibernate.SQL">
      <level name="DEBUG"/>
</logger>

Add these to hibernate.cfg.xml

将这些添加到 hibernate.cfg.xml

<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="use_sql_comments">true</property>

回答by CHHIBI AMOR

You can enable or disable logging of the following categories (using a log4j.properties file here):

您可以启用或禁用以下类别的日志记录(在此处使用 log4j.properties 文件):

log4j.properties

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

休眠文件.cfg.xml

<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="use_sql_comments">true</property>