7 Replies Latest reply on Aug 16, 2017 11:45 AM by jamezp

    Wildfly : Logging SQL statements on application log file

    zecas

      Hi,

       

      I need your help on understanding a situation that is happening on logging in an application running on Wildfly 10.1.0 (final).

       

      The application was migrated from being a JavaEE 5 application running on JBoss 5.1.0 GA, to being a JavaEE 7 application running on Wildfly 10.1.0 (final).

       

      The problem is that on Wildfly, the SQL statements are not being logged, but in JBoss 5.1.0 GA they were logging correctly on the application log file (configured on "logback.xml").

       

      The application is packed as an EAR with a WEB and EJB module, and contains the following file:

       

      [app-ear-1.0.0.ear]/META-INF/jboss-deployment-structure.xml

       

      <jboss-deployment-structure>
          <deployment>
              <exclusions>
                  <module name="org.slf4j" />
                  <module name="org.slf4j.impl" />
              </exclusions>
          </deployment>
          <sub-deployment name="app-ejb-1.0.0.jar">
              <exclusions>
                  <module name="org.slf4j" />
                  <module name="org.slf4j.impl" />
              </exclusions>
          </sub-deployment>
          <sub-deployment name="app-web-1.0.0.war">
              <exclusions>
                  <module name="org.slf4j" />
                  <module name="org.slf4j.impl" />
              </exclusions>
          </sub-deployment>
      </jboss-deployment-structure>
      

       

      The application uses SLF4J and Logback for logging purposes, and the log file is being written with the application logs.

       

      The "logback.xml" is something like:

       

      <configuration>
      
          <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
              ...
          </appender>
      
          <logger name="my.app.package" level="debug" />
          <logger name="org.hibernate.SQL" level="debug" />
      
          <root level="warn">
              <appender-ref ref="FILE" />
          </root>
      
      </configuration>
      

       

       

      I've searched around the web for solutions, and I've tested several scenarios, like for instance the following ones:

       

       

      1# Excluded logging subsystem by using the following "jboss-deployment-structure.xml" contents, with no change on results:

       

      <jboss-deployment-structure>
          <deployment>
              <exclude-subsystems>
                  <subsystem name="logging" />
              </exclude-subsystems>
          </deployment>
          <sub-deployment name="app-ejb-1.0.0.jar">
              <exclude-subsystems>
                  <subsystem name="logging" />
              </exclude-subsystems>
          </sub-deployment>
          <sub-deployment name="app-web-1.0.0.war">
              <exclude-subsystems>
                  <subsystem name="logging" />
              </exclude-subsystems>
          </sub-deployment>
      </jboss-deployment-structure>
      

       

       

      2# Added the following logger category on "standalone-full.xml" config:

       

      <profile>
          <subsystem xmlns="urn:jboss:domain:logging:3.0">
             <logger category="org.hibernate.SQL">
                  <level name="DEBUG"/>
              </logger>
          </subsystem>
          ...
      </profile>
      

       

      This started logging the sql statements, but on "server.log" and not on the application log file, as intended.

       

       

      3# Since the above scenario showed some progress, I've added "log4j-over-slf4j" bridging lib to the project, in an attempt to redirect logging to SLF4J framework on the application, but still no statements were logged on the application log file.

       

       

      Can anyone give me any tips on how to accomplish what I intended?

       

      I need hibernate SQL statements to be logged on the application log file, instead of the "server.log".

       

       

      Thank you for your help.