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 'https://github.com/downloads/logentries/le_java/leappender-1.1.5.jar'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 leappender-1.1.5.bar; jar -cvfm leappender-1.1.5.bar leappender/META-INF/MANIFEST.MF -C leappender .
# Wrap it first using bnd
wget -O bnd.jar 'http://search.maven.org/remotecontent?filepath=biz/aQute/bnd/1.50.0/bnd-1.50.0.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/startup.properties.
The system folder has a “Maven repo like” structure. So you have to copy with:

system/groupId/artifactId/version/artifactId-version.jar


In our example, it means:
mkdir -vp system/com/logentries/leappender/1.1.5/cp -v leappender-1.1.5.bar system/com/logentries/leappender/1.1.5/leappender-1.1.5.jar
and in etc/startup.properties, we define the appender bundle just before the pax-logging-service bundle:
...
org/ops4j/pax/logging/pax-logging-api/1.
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
log4j.appender.
le=com.logentries.log4j.LeAppender
log4j.appender.
le.Token=LOGENTRIES_TOKEN
log4j.appender.
le.Debug=true
log4j.appender.
le.layout=org.apache.log4j.PatternLayout
log4j.appender.
le.layout.ConversionPattern=%d{ISO8601} | %-5.5p | %-16.16t | %-32.32c{1} | %-32.32C %4L | %X{bundle.id} - %X{bundle.name} - %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! :-)
References:

9 comments:

essayswriters said...

Logentries is a nice way to track your server/application logs. Free account available. :)
I blogged this how to at :
http://essayswriters.org/assignment/
Hope this is useful.

www.writemypapers.org said...

It's really one of the best and the easiest ways. Thanks.

special-essays said...

Thanks for useful info!

Buy Essay said...

hey that's really a great post and i like this and thanks for sharing it with us! :)
Writings-centre.com

Kat said...

Information is really useful. Thanks for sharing! Here at http://top-writing-services.com you can also find interesting information.

Amy Pearson said...

Great post! To find more info, follow the link!

alexxlexx said...

Thanks for help, you can find out more at http://prime-essay.org

fitflop uk said...

After basically michael kors outlet out her coach factory assets tiffany and co jewelery in a low-coach factory blazer ensemble, the michael kors outlet reality coach outlet star louis vuitton handbags showed louis vuitton outlet off her coach factory outlet curves in ray ban sunglasses a see-tory burch outlet lace michael kors outlet this oakley sunglasses cheap week. But coach factory outlet worry, she coach store online bra this valentino time. I love coach outlet the louis vuitton outlet minimalist air jordan aesthetic true religion jeans brought to coach factory. He cheap ray ban sunglasses knows that timberland shoes because tory burch spending top prada outlet doesn't true religion outlet mean you coach factory outlet extra coach outlet store online bells <a href="http://www.officialcoachfactoryoutlet.com/"

Amira Taylor said...

The information you shared through your post is functional.I can also advice you express-essays.com

Post a Comment

 
Copyright 2009 Spring vs Java EE Web Dev. Powered by Blogger Blogger Templates create by Deluxe Templates. WP by Masterplan