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

    log4j configuration in wildfly 9

    Sumanth Bandi Newbie

      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);

      }