Enterprise Integration Zone is brought to you in partnership with:

Jason began his career working on EAI systems that covered a breadth of technologies ranging from Java Script, Java, C++, C#, to Silverlight. He has also spent a considerable amount of time working on systems which used WebSphere MQ as the middleware layer. Jason is now fortunate enough to work full time with products such as Apache ActiveMQ, Apache Camel, and Apache ServiceMix. Jason is a DZone MVB and is not an employee of DZone and has posted 10 posts at DZone. You can read more from them at their website. View Full User Profile

SerivceMix: Configuring Sift Appender with a Rolling Log File

03.04.2013
| 3881 views |
  • submit to reddit

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  



Published at DZone with permission of Jason Sherman, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)