-
1. Re: Logging SQL Statements in EAP 6.1
aaroncirillo Jul 3, 2014 1:56 PM (in response to aaroncirillo)I got some help on the wildfly IRC channel. The problem was that my console handler was set to INFO, so I guess it was filtering out any TRACE messages that were being generated. This is the modification I made in standalone.xml:
<console-handler name="CONSOLE">
<level name="TRACE"/>
<formatter>
<pattern-formatter pattern="%K{level}%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
</formatter>
</console-handler>
Thanks to double_p in #wildfly on freenode for the answer here. I can now see all of the SQL being generated on the datasource I enabled the spy logging on.
-
2. Re: Logging SQL Statements in EAP 6.1
masummymesingh Nov 23, 2014 1:16 PM (in response to aaroncirillo) -
3. Re: Logging SQL Statements in EAP 6.1
rsandoz1 Apr 7, 2017 11:15 AM (in response to aaroncirillo)I know this is old, but it is the first thing I found on google with "logging SQL with jboss". Anyway, spy works great, but it floods the log way too much for an enterprise level application. One thing I noticed is a line for every ResultSet item. In case you, like me, don't want this, I use a tag called <filter-spec> to clean these out:
<console-handler name="CONSOLE">
<filter-spec value="not(match("\\[ResultSet\\]"))"/>
-
4. Re: Logging SQL Statements in EAP 6.1
andey Apr 10, 2017 2:01 PM (in response to aaroncirillo)Hi,
In order to enable the above logging in EAP 6, add the following
<logger>
configuration insidelogging
subsystem (instandalone(-*).xml for standalone mode /
domain.xml` for domain mode):~~~
<subsystem xmlns="urn:jboss:domain:logging:1.2">
<console-handler name="CONSOLE">
...(snip)...
</console-handler>
<periodic-rotating-file-handler name="FILE" autoflush="true">
...(snip)...
</periodic-rotating-file-handler>
...(snip)...
<!-- ADDED THE FOLLOWING -->
<logger category="org.hibernate.SQL">
<level name="DEBUG"/>
</logger>
<logger category="org.hibernate.type">
<level name="TRACE"/>
</logger>
<!-- ADDED ABOVE LINES-->
<root-logger>
...(snip)...
</root-logger>
</subsystem>~~~
You can also:
JBoss EAP 6 provides a very efficient way of enabling the spy logging which can log all the information related to the connections/statements and any method which is invoked on the JDBC Objects.
Add the category jboss.jdbc.spy in the logging subsystem related to your configuration file standalone*.xml or if you run in domain mode to the related profile of the domain.xml.
Add the spy flag to the datasource
The datasource contain an attribute to enable the jdbc logging. The attribute spy is set to false by default.
~~~
<datasource jndi-name="java:boss/datasources/MySQLDS" pool-name="MySQLDS_Pool" enabled="true" spy="true">
~~~
Note: It is possible to use separate datasource configurations, so it is important to check if your server contains such separate files for datasource configuration in development, then you will need to add this parameter on that separated file.
Enable the logging
~~~
<logger category="jboss.jdbc.spy">
<level name="TRACE"/>
</logger>
~~~
Use CLI to enable monitoring
To enable the datasource spy flag and add the logger the following CLI commands can be used.
~~~
/subsystem=logging/logger=jboss.jdbc.spy:add(level=TRACE)
# optional to enable log output in the console
/subsystem=logging/console-handler=CONSOLE:write-attribute(name=level, value=TRACE)
/subsystem=datasources/data-source=MySQLDS_Pool:write-attribute(name=spy, value=true)
~~~
Remember that the commands must use the profile=ProfileName prefix if the domain mode is used.
You need to restart the server to enable the spy logging. Remember that the DEBUG logging will not shown at the CONSOLE by default.