Platinum Partner
java,enterprise-integration,integration,esb,tips and tricks,servicemix

SerivceMix: Configuring Sift Appender with a Rolling Log File

I have come across several issues where people were having trouble configuring the Sift file appender in ServiceMix to enable per bundle logging.  Specifically, issues arose when trying to configure a rolling log file appender for sift.  This is rather simple and straight forward as you will see in the configuration below.  You simply need to use the org.apache.log4j.RollingFileAppender as you would for any log4j appender.  The important part is ensuring the proper configuration when applying the rolling log file appender to sift.

Lets have a look at the org.ops4j.pax.logging.cfg of the latest distribution of Fuse ESB, which is currently 4.4.1-fuse-03-06.  The Sift appender comes configured as follows:

 # 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  

To enable a rolling log file we need to change:

log4j.appender.sift.appender=org.apache.log4j.FileAppender

to:

 log4j.appender.sift.appender=org.apache.log4j.RollingFileAppender  

Then we need to add the following properties to enable the rolling log:

 log4j.appender.sift.appender.maxFileSize=10MB   
 log4j.appender.sift.appender.maxBackupIndex=10  

Of course you would configure these properties as required by your application.

Now the Sift appender configured for rolling log files should look as follows:

 # 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.RollingFileAppender  
 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.appender.sift.appender.maxFileSize=10MB   
 log4j.appender.sift.appender.maxBackupIndex=10  

That's all there is to it.  You now have a Sift appender configured for rolling log files.  Just remember you also need to have the rootLogger configured as follows to ensure the sift appender is activated.

Note: This is found at the top of the org.ops4j.pax.logging.cfg file.

 log4j.rootLogger=INFO, sift, osgi:VmLogAppender  



{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}