4 Replies Latest reply on Dec 12, 2017 10:10 AM by rabbit10

    Configure wildfly's subsystems to use log4j instead of default logging framework

    rabbit10

      Hi all, I would like to use log4j as logging framework instead of wildlfy's default for its subsystems (messaging subsystem in particular). I already have log4j in my applications running on wildfly (10.1). Reason behind this is to configure appender (log4j HttpAppender) for WARN logs coming from messaging subsystem. I want to do this in order to be able to receive info about this warning being logged https://developer.jboss.org/message/978735#978735. Is there way to replace default wildlfy logging subsystem with log4j or to configure messaging subsystem to use log4j instead of logging? Does wildlfly's logging subsystem has some sort of HTTP appenders? Is there place where I can see if/what appenders it supports? Thank you in advance! Regards!

        • 1. Re: Configure wildfly's subsystems to use log4j instead of default logging framework
          ctomc

          you can configure/use any log4j appenders in logging subsystem configuration.

          for example look at how log4j's SMTP appender can be configured at wildfly 10 mail logger

          1 of 1 people found this helpful
          • 2. Re: Configure wildfly's subsystems to use log4j instead of default logging framework
            rabbit10

            Thank you for response!

             

            I have followed the example to configure SMTP appender and configured it successfully.

             

            However, when I tried to configure HTTP appender it failed.

             

            With following configuration

             

                       <custom-handler name="httpHandler" class="org.apache.log4j.net.HTTPAppender" module="org.apache.log4j">

                            <level name="INFO"/>

                            <formatter>

                                <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>

                            </formatter>

                            <properties>

                                <property name="url" value="https://requestb.in/17d0tfy1"/>

                            </properties>

                        </custom-handler>

             

            it failed with

             

            2017-12-12 13:50:29,006 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([

                ("subsystem" => "logging"),

                ("custom-handler" => "httpHandler")

            ]) - failure description: "WFLYLOG0021: Class 'org.apache.log4j.net.HttpAppender' could not be found."

             

            Generally I get this error if I set something invalid for "class".

             

            I have checked fully qualified name of HTTP appender and tried to set that class name:

             

            <custom-handler name="httpHandler" class="org.apache.logging.log4j.core.appender.HttpAppender" module="org.apache.logging.log4j">

             

             

            but now error is following:

             

            2017-12-12 13:52:34,866 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([

                ("subsystem" => "logging"),

                ("custom-handler" => "httpHandler")

            ]): java.lang.IllegalArgumentException: Failed to load class "org.apache.logging.log4j.core.appender.HttpAppender" for handler "httpHandler"

                    at org.jboss.logmanager.config.AbstractPropertyConfiguration.<init>(AbstractPropertyConfiguration.java:73)

                    at org.jboss.logmanager.config.HandlerConfigurationImpl.<init>(HandlerConfigurationImpl.java:51)

                    at org.jboss.logmanager.config.LogContextConfigurationImpl.addHandlerConfiguration(LogContextConfigurationImpl.java:142)

                    at org.jboss.as.logging.logmanager.ConfigurationPersistence.addHandlerConfiguration(ConfigurationPersistence.java:190)

                    at org.jboss.as.logging.HandlerOperations$HandlerAddOperationStepHandler.createHandlerConfiguration(HandlerOperations.java:311)

                    at org.jboss.as.logging.HandlerOperations$HandlerAddOperationStepHandler.performRuntime(HandlerOperations.java:229)

                    at org.jboss.as.logging.LoggingOperations$LoggingAddOperationStepHandler$1.execute(LoggingOperations.java:204)

                    at org.jboss.as.controller.AbstractOperationContext.executeStep(AbstractOperationContext.java:890)

                    at org.jboss.as.controller.AbstractOperationContext.processStages(AbstractOperationContext.java:659)

                    at org.jboss.as.controller.AbstractOperationContext.executeOperation(AbstractOperationContext.java:370)

                    at org.jboss.as.controller.OperationContextImpl.executeOperation(OperationContextImpl.java:1329)

                    at org.jboss.as.controller.ModelControllerImpl.boot(ModelControllerImpl.java:493)

                    at org.jboss.as.controller.AbstractControllerService.boot(AbstractControllerService.java:387)

                    at org.jboss.as.controller.AbstractControllerService.boot(AbstractControllerService.java:349)

                    at org.jboss.as.server.ServerService.boot(ServerService.java:397)

                    at org.jboss.as.server.ServerService.boot(ServerService.java:366)

                    at org.jboss.as.controller.AbstractControllerService$1.run(AbstractControllerService.java:299)

                    at java.lang.Thread.run(Thread.java:748)

            Caused by: java.lang.ClassCastException: class org.apache.logging.log4j.core.appender.HttpAppender

                    at java.lang.Class.asSubclass(Class.java:3404)

                    at org.jboss.logmanager.config.AbstractPropertyConfiguration.<init>(AbstractPropertyConfiguration.java:71)

                    ... 17 more

             

            I am using log4j 2.9.1 (as HttpAppender is added from 2.9 version).

             

            I also found that Smtp appender fully qualified name is "org.apache.logging.log4j.core.appender.SmtpAppender", but standalone.xml successfully configurs SMTP appender when "org.apache.log4j.net.SMTPAppender" is set.

             

            Am I missing something in configuration?

             

            EDIT: I have found that org.apache.log4j.net.SMTPAppender is class inside og4j-jboss-logmanager-1.1.2.Final.jar and there is no HttpAppender so I assume HttpAppender is not supported by wildfly. And if I want HttpAppender I would have to implement it. Are my conclusions correct?

            • 3. Re: Configure wildfly's subsystems to use log4j instead of default logging framework
              ctomc

              Just add module that has jar with that module in it.

               

              and than in appender config reference that module.

              • 4. Re: Configure wildfly's subsystems to use log4j instead of default logging framework
                rabbit10

                I have configured    <module name="org.apache.logging.log4j" slot="main"/> in global modules.

                 

                and log4j jar that has HttpAppender is in modules:

                 

                [root@myhost main]# pwd

                /opt/wildfly/modules/system/layers/base/org/apache/logging/log4j/main

                [root@myhost main]# ls

                log4j-api-2.9.1.jar  log4j-core-2.9.1.jar  module.xml

                [root@myhost main]# cat module.xml

                <?xml version="1.0" encoding="UTF-8"?>

                <module xmlns="urn:jboss:module:1.1" name="org.apache.logging.log4j">

                        <resources>

                                <resource-root path="log4j-api-2.9.1.jar"/>

                        <resource-root path="log4j-core-2.9.1.jar"/>

                        </resources>

                        <dependencies>

                        <module name="javax.servlet.api" export="true"/>

                        <module name="javax.api" export="true"/>

                    </dependencies>

                </module>

                 

                      

                I also tried adding  <module name="org.apache.logging.log4j" export="true"/> to module.xml but got same exception.

                 

                What am I missing to configure?