1 Reply Latest reply on Jul 21, 2016 1:16 PM by James Perkins

    Log4j2 support for wildfly

    Nick . Apprentice

      Just wondering is it possible to use Log4j2 in our application running in wildfly 10, since Wildfly have its own logging implementation with log4j1, its messing up if we introduce log4j2. The following problems i found while we use Log4j2 for logging


      1) If create wildfly module for log4j2, and add this module in jboss-deployment-structure.xml, application is not starting while Hibernate loads entitt classes and throws ClassDefinitionNotFound Exception for Log4jContextFactory


      2) If we disable log4j and slf4j from auto import in jboss-deployment-structure.xml,  and add Log4j2 dependency libraries to our EAR/lib/ folder then application starting up and logs are written to file as well as Console but all logs are writing into stdout ie we are getting our info message like INFO [stdout].

      Any help how we can integrate log4j2 with jboss logging subsystem ?


        • 1. Re: Log4j2 support for wildfly
          James Perkins Master

          I don't know how contexts are determined in log4j2, but I'd assume it's easiest to  include log4j2 in your deployment. Essentially like you're doing in your second option. Using a module may be problematic if each deployment has it's own configuration as one deployment would win with regards to the log manager configuration.


          The console logging can be a bit tricky. Because WildFly wraps both System.out and System.err in loggers anything written to those streams will go through the servers log manager. One option around this is to use your own ConsoleAppender that doesn't writ directly to System.out or System.err. You can use the FileDescriptor and PrintStream instead like is do in the forked version of log4j provided by WildFly.


          Your other option is to define a new console-handler on WildFly that just uses a pattern of %s. Then add a logger for stdout and/or stderr and add the handler to each logger. The following CLI commands should give you the desired outcome.

          /subsystem=logging/console-handler=streams:add(autoflush=true, named-formatter=PLAIN, target=System.out)
          /subsystem=logging/logger=stdout:add(handlers=[streams], use-parent-handlers=false)



          James R. Perkins