Saturday, December 29, 2012

Setting Up logentries for OSGi Applications in Apache Karaf

What You'll Get


How To

Get an account at logentries. For a start, you'll get free forever account for 1 GB of logs per month, which is cool. :-)
We need to patch leappender-1-1.5.jar by adding OSGi manifest headers and attach it as fragment to pax-logging-service. (in CentOS/Amazon Linux, jar requires java-1.7.0-openjdk-devel yum package)
wget ''unzip -d leappender leappender-1.1.5.jarmkdir -vp leappender/META-INF
nano leappender/META-INF/MANIFEST.MF
Replace with:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: com.logentries.leappender
Bundle-SymbolicName: com.logentries.leappender
Bundle-Version: 1.1.5
Created-By: 1.7.0_09-icedtea (Oracle Corporation)
Export-Package: com.logentries.log4j;uses:="org.apache.log4j.spi";version="1.1.5"
Import-Package: org.apache.log4j,org.apache.log4j.spi
Fragment-Host: org.ops4j.pax.logging.pax-logging-service
rm -v; jar -cvfm leappender/META-INF/MANIFEST.MF -C leappender .
# Wrap it first using bnd
wget -O bnd.jar ''
java -jar bnd.jar wrap leappender-1.1.5.jar

our appender bundle should be present in the system folder and defined in etc/
The system folder has a “Maven repo like” structure. So you have to copy with:


In our example, it means:
mkdir -vp system/com/logentries/leappender/1.1.5/cp -v system/com/logentries/leappender/1.1.5/leappender-1.1.5.jar
and in etc/, we define the appender bundle just before the pax-logging-service bundle:
7.0/pax-logging-api-1.7.0.jar=8com/logentries/leappender/1.1.5/leappender-1.1.5.jar=8 org/ops4j/pax/logging/pax-logging-service/1.7.0/pax-logging-service-1.7.0.jar=8
Edit Karaf's etc/org.ops4j.pax.logging.cfg :
log4j.rootLogger = INFO, out, le, osgi:*
# Logentries appender
le.layout.ConversionPattern=%d{ISO8601} | %-5.5p | %-16.16t | %-32.32c{1} | %-32.32C %4L | %X{} - %X{} - %X{bundle.version} | %m%n
log4j.appender.le.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss ZZZ} %-5p: %F:%L %m
Note: The LOGENTRIES_TOKEN parameter can be found beside the logfile which we created earlier.
I can't get this to work automatically, so on first Karaf launch you'll get ClassNotFoundException, then you'll need to install it:
install mvn:com.logentries/leappender/1.1.5
bundle-level <id> 8
Now it should work.
At first launch you'll get a ClassNotFound exception. Shutdown Karaf and relaunch, it should work. (this was due to the leappender-1.1.5.jar in deploy/ folder, the system one still doesn't work automatically)
Happy logging! :-)
Copyright 2009 Spring vs Java EE Web Dev. Powered by Blogger Blogger Templates create by Deluxe Templates. WP by Masterplan