2 Replies Latest reply on Sep 4, 2015 11:50 AM by jamezp

    log4j configuration in wildfly 9

    sumanthreddybandi

      I am migrating an application from JBoss 4.2.3 to Wildfly 9. Application is a EAR file which is using default jboss-log4j.xml and WAR is using custom log4j-war.xml

       

      The current setup is working like all log statements in EAR/EJB_JAR are logged at server.log. But WAR log statements are logged into a different log file.

       

      I am using default log4j-jboss-logmanager.jar instead of traditional log4j.jar

       

      I am getting the below exception when i login to the application. Please suggest

       

      Servlet Path: /login

      Path Info: null

      Query String: null

       

      Stack Trace

      java.lang.SecurityException: Not supported in log4j-jboss-logmanager

      org.apache.log4j.LogManager.setRepositorySelector(LogManager.java:45)

      com.test.myProjectPilot.util.MyRepositorySelector.init(MyRepositorySelector.java:49)

      com.test.myProjectPilot.servlet.LoginServlet.init(LoginServlet.java:51)

      io.undertow.servlet.core.LifecyleInterceptorInvocation.proceed(LifecyleInterceptorInvocation.java:117)

      org.wildfly.extension.undertow.security.RunAsLifecycleInterceptor.init(RunAsLifecycleInterceptor.java:78)

      io.undertow.servlet.core.LifecyleInterceptorInvocation.proceed(LifecyleInterceptorInvocation.java:103)

      io.undertow.servlet.core.ManagedServlet$DefaultInstanceStrategy.start(ManagedServlet.java:230)

      io.undertow.servlet.core.ManagedServlet.getServlet(ManagedServlet.java:169)

      io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)

       

       

      It is failing at LogManager.setRepositorySelector(theSelector, guard);

       

      private static boolean initialized = false;

      private static Object guard = LogManager.getRootLogger();

      private static LoggerRepository defaultRepository;

      public static synchronized void init(ServletConfig config) throws ServletException {

            if( !initialized ) // set the global RepositorySelector

            {

               defaultRepository = LogManager.getLoggerRepository();

               RepositorySelector theSelector = new MyRepositorySelector();

               LogManager.setRepositorySelector(theSelector, guard);

               initialized = true;

            }

            Hierarchy hierarchy = new Hierarchy(new RootCategory(Level.DEBUG));

            loadLog4JConfig(config, hierarchy);

            ClassLoader loader = Thread.currentThread().getContextClassLoader();

            repositories.put(loader, hierarchy);

      }

        • 1. Re: log4j configuration in wildfly 9
          sumanthreddybandi

          log4j-jboss**.jar doesn't support this method: LogManager.setRepositorySelector(theSelector, guard);

           

          I just commented that line and it is working fine

          1 of 1 people found this helpful
          • 2. Re: log4j configuration in wildfly 9
            jamezp

            I'd suggest either using the logging subsystem to configure logging or a log4j configuration file rather than configuring a log manager like this.

             

            You also shouldn't need to include the log4j-jboss-logmanager dependency in your deployment. During the deployment process a dependency is added to a deployment for org.apache.log4j which is aliased to org.jboss.log4j.manager.

             

            --

            James R. Perkins