1 Reply Latest reply: Mar 7, 2012 3:18 AM by Claus Ibsen RSS

    Separate Log Files Per Bundle

    Eric Bender Newbie

      Hello all, 

       

      As more developer start working within the servicemix framework, I am trying to setup so that each deployed application bundle writes to it's own log file.

       

      I tried what is listed at http://fusenotes.blogspot.com/2011/02/logging-per-application-in-servicemix-4.html and that seems to make the system write to different log files based on the bundle, but in our routes the use of the log EIP  still writes to the servicemix.log. 

       

      What is the best method to have a custom bundle write to it's own log file?

       

      My etc/org.ops4j.pax.logging.cfg looks like this

       

      
      # Root logger
      log4j.rootLogger = INFO, out, sift, osgi:VmLogAppender
      log4j.throwableRenderer=org.apache.log4j.OsgiThrowableRenderer
      
      log4j.appender.sift.key=app.name
      log4j.appender.sift.appender.file=${karaf.data}/log/$\\{app.name\\}.log
      
      # CONSOLE appender not used by default
      log4j.appender.stdout=org.apache.log4j.ConsoleAppender
      log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
      log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} | %-5.5p | %-16.16t | %-32.32c{1} | %X{bundle.id} - %X{bundle.name} - %X{bundle.version} | %m%n
      
      # File appender
      log4j.appender.out=org.apache.log4j.RollingFileAppender
      log4j.appender.out.layout=org.apache.log4j.PatternLayout
      log4j.appender.out.layout.ConversionPattern=%d{ABSOLUTE} | %-5.5p | %-16.16t | %-32.32c{1} | %X{bundle.id} - %X{bundle.name} - %X{bundle.version} | %m%n
      log4j.appender.out.file=${karaf.data}/log/servicemix.log
      log4j.appender.out.append=true
      log4j.appender.out.maxFileSize=100MB
      log4j.appender.out.maxBackupIndex=10
      
      # Sift appender
      log4j.appender.sift=org.apache.log4j.sift.MDCSiftingAppender
      log4j.appender.sift.key=bundle.name
      log4j.appender.sift.default=servicemix
      log4j.appender.sift.appender=org.apache.log4j.FileAppender
      log4j.appender.sift.appender.layout=org.apache.log4j.PatternLayout
      log4j.appender.sift.appender.layout.ConversionPattern=%d{ABSOLUTE} | %-5.5p | %-16.16t | %-32.32c{1} | %m%n
      log4j.appender.sift.appender.file=${karaf.data}/log/$\\{bundle.name\\}.log
      log4j.appender.sift.appender.append=true
      log4j.logger.org.apache.camel = INFO
      

       

      and I am using a simple spring method invoc in my beans.xml

       

      
           <bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
                <property name="targetClass">
                     <value>org.slf4j.MDC</value>
                </property>
                <property name="targetMethod">
                     <value>put</value>
                </property>
                <property name="arguments">
                     <list>
                          <value>app.name</value>
                          <value>MDM-RealTime</value>
                     </list>
                </property>     
           </bean>