2

I was trying to get Spring 4 to log in Wildfly 8.2. I wanted spring to use the wildfly logging configuration.

All the examples I could find were trying to complicate this process by adding additional logging frameworks and configuration.

So here is how I did it, for prosperity.

Rian
  • 1,243
  • 2
  • 17
  • 22

3 Answers3

5

To get spring 4 to log in wildfly 8, I had to add the following to the logging subsystem config in the standalone.xml file.

<add-logging-api-dependencies value="false"/>
<use-deployment-logging-config value="false"/>

Additionally to get debug logging

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

Here is the full subsystem config:

    <subsystem xmlns="urn:jboss:domain:logging:2.0">
            <add-logging-api-dependencies value="false"/>
            <use-deployment-logging-config value="false"/>
            <console-handler name="CONSOLE">
                <level name="DEBUG"/>
                <formatter>
                    <named-formatter name="COLOR-PATTERN"/>
                </formatter>
            </console-handler>
            <periodic-rotating-file-handler name="FILE" autoflush="true">
                <formatter>
                    <named-formatter name="PATTERN"/>
                </formatter>
                <file relative-to="jboss.server.log.dir" path="server.log"/>
                <suffix value=".yyyy-MM-dd"/>
                <append value="true"/>
            </periodic-rotating-file-handler>
            <logger category="com.arjuna">
                <level name="WARN"/>
            </logger>
            <logger category="org.apache.tomcat.util.modeler">
                <level name="WARN"/>
            </logger>
            <logger category="org.springframework">
                <level name="DEBUG"/>
            </logger>
            <logger category="org.jboss.as.config">
                <level name="DEBUG"/>
            </logger>
            <logger category="sun.rmi">
                <level name="WARN"/>
            </logger>
            <logger category="jacorb">
                <level name="WARN"/>
            </logger>
            <logger category="jacorb.config">
                <level name="ERROR"/>
            </logger>
            <root-logger>
                <level name="INFO"/>
                <handlers>
                    <handler name="CONSOLE"/>
                    <handler name="FILE"/>
                </handlers>
            </root-logger>
            <formatter name="PATTERN">
                <pattern-formatter pattern="%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
            </formatter>
            <formatter name="COLOR-PATTERN">
                <pattern-formatter pattern="%K{level}%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
            </formatter>
        </subsystem>
Rian
  • 1,243
  • 2
  • 17
  • 22
1

The answer depends on what causes the deployment to break in your deployment.

If you have any of the following logging classes in your classpath that can cause logging to break: logging.properties, jboss-logging.properties, log4j.properties, log4j.xml, jboss-log4j.xml

So for example just run this code (either in your app or in a debugger) and it'll show you if you have the file in the classpath

getClass().getResource("/logging.properties")

Repeat for each of the log files specifed above, if any of those return non-null then you have found your culprit.

At that stage you can either remove the problem logging file, or alternatively use Rian's suggestion of adding <use-deployment-logging-config value="false"/> (you don't need to use add-logging-api-dependencies in that scenario thou).

Another potential issue if you have multiple logging jar files. Keep in mind that wildfly will automatically provide several of those unless you use <add-logging-api-dependencies value="false"/>

Yannick Menager
  • 305
  • 2
  • 9
0

I had this similar problem and I got it working thanks to the first answer posted by Rian. Here is my working system:

  • Server: jBoss EAP 7.1
  • Framework: Spring 5
  • Configuration via: yml
  • Modules: each module has its own independent war deployed
  • Requirement: Each module must log in a separated file

In the yml file I added the following lines to set the log output to a different file than the standar server.log:

logging:
  file: ${SPF_LOGGING_PATH:app-logs/}log-@project.artifactId@-app.log
  pattern:
    console: "%d %-5level %logger : %msg%n"
    file: "%d %-5level [%thread] %logger : %msg%n"

Using this configuration, a file in the output dir is created but no text is been written. So, adding this lines to the logging subsystem section in standalone.xml file, it started to write text from each module:

<add-logging-api-dependencies value="false"/>
<use-deployment-logging-config value="false"/>

Hope this may help anyone facing the same issue. Cheers!

marcello
  • 165
  • 2
  • 9