DZone
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
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

UK-US Data Bridge: Join TechnologyAdvice and OneTrust as they discuss the UK extension to the EU-US Data Privacy Framework (DPF).

Migrate, Modernize and Build Java Web Apps on Azure: This live workshop will cover methods to enhance Java application development workflow.

Kubernetes in the Enterprise: The latest expert insights on scaling, serverless, Kubernetes-powered AI, cluster security, FinOps, and more.

A Guide to Continuous Integration and Deployment: Learn the fundamentals and understand the use of CI/CD in your apps.

Related

  • Eclipse JNoSQL 1.0.2: Empowering Java With NoSQL Database Flexibility
  • Building a MongoDB-Powered RESTful Application With Quarkus and Eclipse JNoSQL
  • Eclipse JNoSQL 1.0.0: Streamlining Java and NoSQL Integration With New Features and Bug Fixes
  • Making A Good Thing Even Better: Google Open Source WindowBuilder and CodePro Profiler

Trending

  • Understanding JWKS (JSON Web Key Set)
  • Architecture Decision Records
  • Introduction To Azure Analytics Architecture Advisor
  • Optimizing Generative AI With Retrieval-Augmented Generation: Architecture, Algorithms, and Applications Overview
  1. DZone
  2. Coding
  3. Frameworks
  4. SLF4J Logging in Eclipse Plugins

SLF4J Logging in Eclipse Plugins

Michael Schnell user avatar by
Michael Schnell
·
Jan. 06, 13 · Interview
Like (1)
Save
Tweet
Share
37.0K Views

Join the DZone community and get the full member experience.

Join For Free

developing with maven and pure java libraries all the time, i never thought it could be a problem to issue a few log statements when developing an eclipse plugin. but it looks like in the imaginary of an eclipse developer everything is always inside the eclipse environment and nothing is outside the eclipse universe.

if you search for the above headline using google, one of the first articles you’ll find is one about the “platform logging facility”. but what about 3rd libraries? they cannot use an eclipse-based logging framework.

in my libraries i use the slf4j api and leave it up to the user to decide what logging implementation (log4j, logback, jdk) he or she wants to use. and that’s exactly what i want to do in eclipse. it was hard to figure out exactly how to do it, but here are the pieces of that puzzle.

phase 1: development

this describes the steps during the development phase of your custom plugin.

step 1: get your libaries into a p2 repository

everything you want to use in eclipse has to be installed from a p2 repository. but most of the libaries i use are in a maven repository. as far as i know there is no such thing as a main p2 repository similar to the “maven central,” and all libraries i found in p2 repositories were pretty old. so you have to create one by yourself.

luckily there is a maven plugin called p2-maven-plugin that converts all your maven jars into a single p2 repository. you can upload the plugin to a folder of your website or simply install it from your local hard drive.

for this example you’ll need the following libraries:

  • org.slf4j:slf4j-api:1.6.6
  • org.slf4j:slf4j-log4j12:1.6.6
  • log4j:log4j:1.2.17
  • org.ops4j.pax.logging:pax-logging-api:1.7.0
  • org.ops4j.pax.logging:pax-logging-service:1.7.0
  • org.ops4j.pax.confman:pax-confman-propsloader:0.2.2

format “groupid:artifactid:version” is as used for the “p2-maven-plugin.” to skip this step you could also use http://www.fuin.org/p2-repository/ .

step 2: install the slf4j api in the eclipse ide

  1. select “help / install new software…”.
    eclipse / help / install
  2. add the p2 repository url and install the “slf4j-api”—you could directly use the folder from step 1 with a file url like this: “file:/pathtoyour/p2-repository/”. instal slf4j api
  3. add the freshly installed “slf4j.api” to your manifest.mf. dependencies in manifest.mf
  4. start using slf4j logs in your code as usual.

phase 2: production

this describes the tasks a user of your custom plugin has to complete to start logging with log4j. the following assumes that your custom plugin is already installed.

step 1: install the log libraries in the eclipse ide

  1. select “help / install new software…”. eclipse / help / install
  2. install the “equinox target components” from the eclipse update site. install equinox target components
  3. add the p2 repository url and install the following plugins:
    • apache log4j
    • ops4j pax confman–properties loader
    • ops4j pax logging–api
    • ops4j pax logging–service

    install log libs

step 2: configure pax logging

  1. set the location for your log configuration in the “eclipse.ini” as “vmarg"
    …
    -vmargs
    -xms40m
    -xmx512m
    -dbundles.configuration.location=<config-dir>
    …
  2. create a folder named “services” in the above “config-dir.”
  3. create log4j properties named “org.ops4j.pax.logging.properties” in “services.”
    log4j.rootlogger=info, file
    log4j.appender.file=org.apache.log4j.fileappender
    log4j.appender.file.file=<path-to-your-log>/example.log
    log4j.appender.file.layout=org.apache.log4j.patternlayout
    log4j.appender.file.layout.conversionpattern=%d{yyyy/mm/dd hh:mm:ss,sss} [%t] %-5p %c %x - %m%n
    log4j.logger.your.package=debug

step 3: activate pax logging

  1. open the “console” view. show console view
  2. select the “host osgi console.” select osgi console
  3. start the following bundles:

    start org.eclipse.equinox.cm
    start org.ops4j.pax.logging.pax-logging-api
    start org.ops4j.pax.logging.pax-logging-service
    start org.ops4j.pax.configmanager
    start logging bundles

now you should be able to see your log statements in the configured “example.log” file.

step 4: changing the configuration

if you want to change the configuration in the “org.ops4j.pax.logging.properties”, simply restart the pax configmanager in the osgi console

stop org.ops4j.pax.configmanager
start org.ops4j.pax.configmanager

happy logging!

Eclipse Log4j

Published at DZone with permission of Michael Schnell, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Eclipse JNoSQL 1.0.2: Empowering Java With NoSQL Database Flexibility
  • Building a MongoDB-Powered RESTful Application With Quarkus and Eclipse JNoSQL
  • Eclipse JNoSQL 1.0.0: Streamlining Java and NoSQL Integration With New Features and Bug Fixes
  • Making A Good Thing Even Better: Google Open Source WindowBuilder and CodePro Profiler

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: