DZone
Java Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Java Zone > Logging RCP Applications With Pax Logging

Logging RCP Applications With Pax Logging

Patrick Paulin user avatar by
Patrick Paulin
·
Jul. 15, 09 · Java Zone · Interview
Like (0)
Save
Tweet
7.23K Views

Join the DZone community and get the full member experience.

Join For Free

adding logging to an rcp application has always been painful. developers have struggled with the best way to incorporate log4j and other logging apis, and in particular with how to make configuration files accessible. some have chosen to use buddy classloading, others have utilized fragments containing the config files.

pax logging to the rescue

i’m happy to say that rcp developers now have another choice - pax logging . there are a few great things about this library:

  • installation is easy. i’ll describe this in a bit.
  • configuration files can be placed in regular folders, either inside of an application bundle or anywhere on a users machine.
  • many logging apis are supported, including log4j, commons logging, jdk logging, slf4j and more. this means that legacy and third-party code can run as-is no matter what logging api they use.

logging configuration with pax confman

because pax logging requires the osgi configuration admin service to work, your first step is to install this service in the form of pax confman. in my last blog post i provided detailed instructions on how to do this.

adding configuration settings

the good news is that once you install pax confman, you’re almost done! pax confman requires the pax logging bundles in order to work, so we only have a few minor steps left.

the first is to add a logging configuration file. when using the osgi configuration admin service, services are identified using a persistent identifier , or pid . developers can choose the pids for their own services, and an implementation of the config admin uses these pids to inject properties into services.

pax confman does this by requiring that a properties file be named based on the pid of the service it is going to configure. for example, the pax logging pid is org.ops4j.pax.logging and so the properties file for this service will be called org.ops4j.pax.logging.properties.

if you created the folder structure suggested in the pax confman setup, simply create a file called org.ops4j.pax.logging.properties in the confadmin/services directory. you can now place whatever logging configuration you like into this file. for instance, here’s what i have for my simple test project:

log4j.rootlogger=debug, a1

log4j.appender.a1=org.apache.log4j.consoleappender
log4j.appender.a1.layout=org.apache.log4j.patternlayout
log4j.appender.a1.layout.conversionpattern=%-4r [%t] %-5p %c %x - %m%n

log4j.logger.com.rcpquickstart.logtest=debug

forcing pax logging to start

just as we did with pax confman, its necessary to force pax logging to start up when our application is launched. to do this, we simply need add the org.ops4j.pax.logging.pax-logging-service bundle to the configuration page of the product configuration editor and set it’s auto-start property to true. if you’ve followed the instructions for installing pax confman, your complete list should look like this:

paxlogging-1

fire it up

that’s all there is to it. start up your rcp application and you should see log messages appear in your console.

paxlogging-2

happy logging!

from http://rcpquickstart.com

Pax (command) application Rich client platform

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • OpenTelemetry in Action: Identifying Database Dependencies
  • Enough Already With ‘Event Streaming’
  • The Engineer’s Guide to Creating a Technical Debt Proposal
  • Choosing Between REST and GraphQL

Comments

Java Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo