6 Replies Latest reply on Jul 6, 2010 3:02 AM by Hans Wolffenbuttel

    How to logging from .esb service

    Denys Newbie

      It interesting how we may logging from .esb services to separate files (i.e. one log per one file)?

      For example, log into jbossesb-server-4.4.GA\server\default\log.
      Because currently it doesn't want to log to file all when service running on JBoss Application server.
      I read some articles from JBoss and it is possibility to setup logger in conf/jboss-log4j.xml - but it is not our choice because we want to setup loggers in services, i.e. pack log4j.xml together with services.

        • 1. Re: How to logging from .esb service
          Tom Fennelly Master

          AFAIK, this is not possible with the App Server. You can only log to the central (global) log. And yes, it sucks :-)

          • 2. Re: How to logging from .esb service
            Tom Fennelly Master

            Sorry... to add there..... what you could of course do is configure different log appenders and then log the different categories to the different appenders. It's still a bit crap, but at least you could use it to generate a log "per services".

            • 3. Re: How to logging from .esb service
              Kevin Conner Master

              An alternative is to define your logging based on the context classloader.

              See http://www.jboss.org/community/docs/DOC-12203 for the generic server details.

              • 4. Re: How to logging from .esb service
                Denys Newbie

                One of my colleguages found the next solution with spring:
                define bean

                <bean id="log4jInitialization"
                 class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
                 <property name="targetClass"
                 value="org.springframework.util.Log4jConfigurer" />
                 <property name="targetMethod" value="initLogging" />
                 <property name="arguments">
                 <list>
                 <value>classpath:log4j.xml</value>
                 </list>
                 </property>
                 </bean>
                


                define log4j.xml
                <?xml version="1.0" encoding="UTF-8"?>
                <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
                <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
                 debug="false">
                
                 <!-- ============================== -->
                 <!-- Append messages to the console -->
                 <!-- ============================== -->
                
                 <!-- ================================= -->
                 <!-- Preserve messages in a local file -->
                 <!-- ================================= -->
                
                 <!-- A size based file rolling appender -->
                 <appender name="SERVICE_FILE"
                 class="org.apache.log4j.RollingFileAppender">
                 <param name="File" value="${jboss.server.log.dir}/swifting.log" />
                 <param name="Append" value="true" />
                 <param name="MaxFileSize" value="500KB" />
                 <param name="MaxBackupIndex" value="1" />
                
                 <layout class="org.apache.log4j.PatternLayout">
                 <param name="ConversionPattern"
                 value="%d %-5p [%t][%c] %m%n" />
                 </layout>
                 </appender>
                
                 <!-- ================ -->
                 <!-- Setup logger -->
                 <!-- ================ -->
                
                 <logger name="com.ourproj">
                 <level value="debug" />
                 <appender-ref ref="SERVICE_FILE" />
                 </logger>
                
                 <logger name="org.springframework">
                 <level value="warn" />
                 <appender-ref ref="SERVICE_FILE" />
                 </logger>
                
                 <logger name="net.sf.ehcache">
                 <level value="warn" />
                 <appender-ref ref="SERVICE_FILE" />
                 </logger>
                
                 <logger name="org.hibernate">
                 <level value="warn" />
                 <appender-ref ref="SERVICE_FILE" />
                 </logger>
                
                 <logger name="org.apache">
                 <level value="warn" />
                 <appender-ref ref="SERVICE_FILE" />
                 </logger>
                
                 <!-- ======================= -->
                 <!-- Setup the Root Logger -->
                 <!-- ======================= -->
                
                </log4j:configuration>
                



                public class OurActionProcessor extends AbstractSpringAction {
                
                private static final Logger logger = Logger
                 .getLogger(SwiftingActionProcessor.class);
                
                
                 public void method() {
                 logger.info("log something");
                 }
                
                }
                


                It works

                • 5. Re: How to logging from .esb service
                  Godwin king Newbie

                  Keep eye on the topic, I'm also trying to find a solution for separate logging in different ESB package, I'm currently integrating some existing project to JBossESB case, just use classloader to load their class and lunch their method, but the log system seems give quite some trouble.

                  • 6. Re: How to logging from .esb service
                    Hans Wolffenbuttel Expert

                    Hi Denys,

                     

                    How does it know not to use the main JBoss logger? Do i need a springaction for it to work? (where did you place your bean?)

                     

                     

                    Regards,

                     

                    Hans