5 Replies Latest reply on Aug 13, 2013 3:58 AM by erhard

    JBoss 7.1.1 logging system messages through per-deployed app or any other

    guatom

      Dear community:

       

      First of all, thanks for reading and having interest in this topic.

       

      Let's go to the point, in a long story short fashion: I want JBoss to use logback for logging system messages. So far, I've managed to get JBoss to use per-deployed app logging via exclusions in jboss-deployment-structure, but only for the application messages; system (meaning JBoss) messages get out through standalone.xml configuration. Is there any way to configure JBoss so it uses per-deployed logging framework (this would be the optimal)? If no, is there any way to change JBoss logging framework?

       

      Thanks in advance. Best regards.

       

      Update: I tried using a VM Argument as follows:

       

      -Dorg.jboss.logging.provider=slf4j 
      

       

      But then I get the following error:

       

      23:28:36,328 INFO  [org.jboss.modules] JBoss Modules version 1.1.1.GA
      23:28:36,500 ERROR [stderr] java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
      23:28:36,501 ERROR [stderr]           at org.jboss.logging.Slf4jLoggerProvider.getLogger(Slf4jLoggerProvider.java:33)
      23:28:36,503 ERROR [stderr]           at org.jboss.logging.LoggerProviders.find(LoggerProviders.java:37)
      23:28:36,505 ERROR [stderr]           at org.jboss.logging.LoggerProviders.<clinit>(LoggerProviders.java:32)
      23:28:36,506 ERROR [stderr]           at org.jboss.logging.Logger.getLogger(Logger.java:2163)
      23:28:36,508 ERROR [stderr]           at org.jboss.logging.Logger.getMessageLogger(Logger.java:2259)
      23:28:36,510 ERROR [stderr]           at org.jboss.logging.Logger.getMessageLogger(Logger.java:2214)
      23:28:36,512 ERROR [stderr]           at org.jboss.msc.service.ServiceLogger.<clinit>(ServiceLogger.java:42)
      23:28:36,513 ERROR [stderr]           at org.jboss.msc.service.ServiceContainerImpl.<clinit>(ServiceContainerImpl.java:90)
      23:28:36,514 ERROR [stderr]           at org.jboss.msc.service.ServiceContainer$Factory.create(ServiceContainer.java:147)
      23:28:36,514 ERROR [stderr]           at org.jboss.as.server.BootstrapImpl.<init>(BootstrapImpl.java:50)
      23:28:36,515 ERROR [stderr]           at org.jboss.as.server.Bootstrap$Factory.newInstance(Bootstrap.java:238)
      23:28:36,515 ERROR [stderr]           at org.jboss.as.server.Main.main(Main.java:95)
      23:28:36,516 ERROR [stderr]           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      23:28:36,516 ERROR [stderr]           at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      23:28:36,517 ERROR [stderr]           at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      23:28:36,518 ERROR [stderr]           at java.lang.reflect.Method.invoke(Unknown Source)
      23:28:36,518 ERROR [stderr]           at org.jboss.modules.Module.run(Module.java:260)
      23:28:36,518 ERROR [stderr]           at org.jboss.modules.Main.main(Main.java:291)
      23:28:36,519 ERROR [stderr] Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory from [Module "org.jboss.logging:main" from local module loader @2cb49d (roots: C:\LANCode\installers\jboss-as-7.1.1.Final\modules)]
      23:28:36,520 ERROR [stderr]           at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)
      23:28:36,521 ERROR [stderr]           at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)
      23:28:36,522 ERROR [stderr]           at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)
      23:28:36,522 ERROR [stderr]           at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:423)
      23:28:36,523 ERROR [stderr]           at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
      23:28:36,523 ERROR [stderr]           at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)
      23:28:36,524 ERROR [stderr]           ... 18 more
      

       

      I though it could be a problem regarding modifications I had done to modules dir in JBOSS_HOME, so I downloaded a fresh new copy of jboss-as-7.1.1.Final.zip, but that didn't solve the problem.

       

      Thanks in advance again!

        • 1. Re: JBoss 7.1.1 logging system messages through per-deployed app or any other
          jamezp

          There is no way to do this at a system level. You can configure your application to use logback, but not the server itself. The server will always use the JBoss Log Manager for it's configuration.

           

          --

          James R. Perkins

          • 2. Re: JBoss 7.1.1 logging system messages through per-deployed app or any other
            guatom

            I'm now certain that I won't be able to get JBoss to use deployment Logging. But I still want JBoss to use SLF4J and source code shows that it might be possible:

             

                static final String LOGGING_PROVIDER_KEY = "org.jboss.logging.provider";
            
                static final LoggerProvider PROVIDER = find();
            
                private static LoggerProvider find() {
                    final LoggerProvider result = findProvider();
                    // Log a debug message indicating which logger we are using
                    result.getLogger("org.jboss.logging").debugf("Logging Provider: %s", result.getClass().getName());
                    return result;
                }
            
                private static LoggerProvider findProvider() {
                    // Since the impl classes refer to the back-end frameworks directly, if this classloader can't find the target
                    // log classes, then it doesn't really matter if they're possibly available from the TCCL because we won't be
                    // able to find it anyway
                    final ClassLoader cl = LoggerProviders.class.getClassLoader();
                    try {
                        // Check the system property
                        final String loggerProvider = AccessController.doPrivileged(new PrivilegedAction<String>() {
                            public String run() {
                                return System.getProperty(LOGGING_PROVIDER_KEY);
                            }
                        });
                        if (loggerProvider != null) {
                            if ("jboss".equalsIgnoreCase(loggerProvider)) {
                                return tryJBossLogManager(cl);
                            } else if ("jdk".equalsIgnoreCase(loggerProvider)) {
                                return tryJDK();
                            } else if ("log4j".equalsIgnoreCase(loggerProvider)) {
                                return tryLog4j(cl);
                            } else if ("slf4j".equalsIgnoreCase(loggerProvider)) {
                                return trySlf4j();
                            }
                        }
                    } catch (Throwable t) {
                    }
                    try {
                        return tryJBossLogManager(cl);
                    } catch (Throwable t) {
                        // nope...
                    }
                    try {
                        return tryLog4j(cl);
                    } catch (Throwable t) {
                        // nope...
                    }
                    try {
                        // only use slf4j if Logback is in use
                        Class.forName("ch.qos.logback.classic.Logger", false, cl);
                        return trySlf4j();
                    } catch (Throwable t) {
                        // nope...
                    }
                    return tryJDK();
                }
            

             

            Code above is used when getLogger is called:

             

                public static Logger getLogger(String name) {
                    return LoggerProviders.PROVIDER.getLogger(name);
                }
            

             

            Which is used when a Logger is requested almost anywhere in JBoss:

             

            import org.jboss.logging.Logger;
            
            protected static final Logger log = Logger.getLogger(...);
            

             

            Based on source coude, I think that it's possible at least to use SLF4J by passing an argument to JBoss, but it just doesn't work.

            • 3. Re: JBoss 7.1.1 logging system messages through per-deployed app or any other
              ctomc

              that is easy to do.

              just remove all logging jars from your deployment. and it will automaticly add system dependancy to slf4j which you can use.

              • 4. Re: JBoss 7.1.1 logging system messages through per-deployed app or any other
                guatom

                Be sure that I'll be trying this. I'll let you know how it goes. Thanks a lot!

                • 5. Re: JBoss 7.1.1 logging system messages through per-deployed app or any other
                  erhard

                  With JBoss 7.2 you can use "Logging Profiles" to get per-deployment-logging (see https://docs.jboss.org/author/display/AS72/Logging+Configuration)