SlideShare a Scribd company logo
The new OSGi LogService 1.4
and integrating with SLF4J
BJ Hargrave, IBM
Log Service
• An OSGi specification for logging
• Introduced in Release 1 in 2000 as an OSGi logging API
• Many other OSGi spec require logging to the Log Service, for example DS
• Pre-whiteboard; pre-log4j/slf4j
• Versions 1.1, 1.2 and 1.3 only made fairly minor updates
• Version 1.4 is a MAJOR update to the API inspired by SLF4J.
Integrating SLF4J and the new OSGi LogService 1.4 - BJ Hargrave (IBM)
Logger
• An interface that allows a bundle to log information, including a message, a
level, an exception, and a ServiceReference object
• Named, typically the name of the class which will log to it
• Associated with the bundle which creates the Logger
• Provides log level specific methods to avoid message formatting work if the log
level is not in effect
• ‘{}’ message placeholders as well as support for java.util.Formatter
placeholders: %s, %d, …
Integrating SLF4J and the new OSGi LogService 1.4 - BJ Hargrave (IBM)
Log Levels
• Six log levels are defined
Log Level Description
AUDIT Always logged
ERROR Error occurred
WARN Non-blocking failure or unwanted event
INFO Normal operation
DEBUG Detailed output useful for developers
TRACE High volume output for tracing purposes
Logger Factory
• OSGi service which is used to obtain Logger objects
• LogService now extends LoggerFactory
• LogService members deprecated
• Logger names form a hierarchy using Java package.Class naming style
• Special Logger named ROOT is the ancestor of all Loggers
• Logger name hierarchy is used to manage Logger configuration
Logger Configuration
• The Logger Admin service is used to
configure Logger Context objects

• Each bundle can have a Logger Context
object which can control the Log Levels for
the Logger objects of that bundle

• Map<String,LogLevel>
com.foo.Bar=INFO
com.foo=DEBUG
com=INFO
ROOT=ERROR
Logger Configuration
• There is also an unnamed “root” Logger Context from which all named Logger
Contexts inherit configuration
• Most people will just need to configure this Logger Context
• Configuration Admin can be used to configure LoggerContexts using PIDs starting
with “org.osgi.service.log.admin”
• PID “org.osgi.service.log.admin” configures the “root” Logger Context
• PID “org.osgi.service.log.admin|<bundle-symbolic-name>”
configures the Logger Context for the bundle
Where does logged information go?
• The OSGi Log Service specification does not say anything about writing
logged information to the console, files, etc.
• This would be done by using the Log Reader Service or the new Log Stream
Provider service
• So the Log Service specification is “broker” between bundles wanting to log
and bundles wanting to consume the logged information
• Such a consuming bundle can be thought of like Appenders in other logging
back ends such as Logback
Log Stream Provider
• Logged information can be thought of as an
ongoing stream of log entries that never
ends having asynchronous arrival

• This fits perfectly with the new OSGi Push
Stream specification!

• So we added a new Log Stream Provider
service which can be uses by a consuming
bundle to receive and process log entries
as a push stream

• The push stream can be primed with the
log history, if any, which is put in the stream
ahead of any new entries
Log Reader Service still remains
• Even though the design of the Log Reader Service predates the advent of the
whiteboard pattern, it remains supported in the specification
• Existing code may use it
• This also allows the Log Stream Provider implementation to be separate from
the Log Service implementation
• Which is handy for Equinox which implements the Log Service specification
in the framework and was not quite ready to require Java 8 (which Push
Stream requires)
Log Entry expanded to hold new information
• Logged information is packaged and delivered as a Log Entry object
• With the new support for named Loggers, we enhanced Log Entry to provide
more information
• name of the Logger
• a sequence number which orders log entries
• thread and stack trace information about the logging call site
Declarative Services support for using Loggers
• DS will support creating and injecting a Logger for the component
implementation class
• If the reference is to the Logger Factory service and the injection target is
Logger for Formatting Logger, then SCR must use the Logger Factory to
create a Logger which is then injected
@Component
public class ExampleImpl implements Example {
@Reference(service=LoggerFactory.class)
// LoggerFactory.getLogger(ExampleImpl.class)
private Logger logger;
@Activate
void activate() { logger.info("initialized"); }
}
But lots of projects use SLF4J?
Lots of projects use SLF4J as their logging API
• When you build an OSGi system, you will probably use a number of bundles
from open source projects that log using SLF4J
• And you will probably use a number of OSGi specification implementations
which log using OSGi Log Service
• So now you have a mix of bundles using different logging APIs and you need
to the logging combined into a single stream
• How to make the twain meet?
Choices
• We can either send the information logged to the OSGi Log Service to the
SLF4J logging backend (e.g. Logback)
• This means all the logged information is controlled by SLF4J logging
backend configuration
• Or we can send the information logged to the SLF4J API to the OSGi Log
Service
• This means all the logged information is controlled by the Logger
configuration in the Logger Admin service
slf4j.osgi
• SLF4J implementation which maps using the SLF4J API, which is a static API,
onto the OSGi Log Service
• CODE!
osgi.logback
• Component which consumes Log Entries and sends them to the Logback
backend
• CODE!
osgi.logback
• See the Apache Felix Logback project for a more capable implementation of
this choice
• http://felix.apache.org/documentation/subprojects/apache-felix-logback.html
Some notes…
• We are using Equinox framework with its in-built Log Service implementation
• So we need configure a log history so our bundles can find past logged
information when they start
• And we need to configure the Loggers so we have some logged information to
process!
• -runproperties: 

equinox.log.history.max=1000,

org.osgi.service.log.admin.loglevel=DEBUG
Thanks!
Evaluate the Sessions
-1 0 +1
Sign in and vote at eclipsecon.org

More Related Content

PDF
OSMC 2021 | Robotmk: You don’t run IT – you deliver services!
PDF
Kuberntes Ingress with Kong
PDF
IXP Manager Workshop
PDF
The Fn Project by Jesse Butler
PDF
Serverless Boston @ Oracle Meetup
PPTX
Blockchain and UDFs
PPTX
Peer council 2013_presentation
PPT
SLF4J (Simple Logging Facade for Java)
OSMC 2021 | Robotmk: You don’t run IT – you deliver services!
Kuberntes Ingress with Kong
IXP Manager Workshop
The Fn Project by Jesse Butler
Serverless Boston @ Oracle Meetup
Blockchain and UDFs
Peer council 2013_presentation
SLF4J (Simple Logging Facade for Java)

What's hot (17)

PDF
Registry improvements update
PDF
(ATS4-DEV05) Pipeline Pilot 9.0 Advanced Protocol Development Topics
PDF
Flink Forward Berlin 2017: Dominik Bruhn - Deploying Flink Jobs as Docker Con...
PDF
Kong API
PDF
Distributed OSGi Services with the Eclipse Communication Framework - Jan Rell...
PPTX
Selenium-4
PDF
OSMC 2021 | Thola – A tool for monitoring and provisioning network devices
PPTX
Rpc framework
PPTX
Multi-Lingual Accumulo Communications
PPTX
Introduction to SoapUI day 3
PPTX
Seif_mike_gsoc_2014_cloudstack
PPTX
Learn Git form Beginners to Master
PDF
Introduction to the Archivematica API (September 2018)
PPTX
Super Size Your Search
PPTX
State of the art logging
PDF
Archivematica Technical Training Diagnostics Guide (September 2018)
PPTX
Automation tools: making things go... (March 2019)
Registry improvements update
(ATS4-DEV05) Pipeline Pilot 9.0 Advanced Protocol Development Topics
Flink Forward Berlin 2017: Dominik Bruhn - Deploying Flink Jobs as Docker Con...
Kong API
Distributed OSGi Services with the Eclipse Communication Framework - Jan Rell...
Selenium-4
OSMC 2021 | Thola – A tool for monitoring and provisioning network devices
Rpc framework
Multi-Lingual Accumulo Communications
Introduction to SoapUI day 3
Seif_mike_gsoc_2014_cloudstack
Learn Git form Beginners to Master
Introduction to the Archivematica API (September 2018)
Super Size Your Search
State of the art logging
Archivematica Technical Training Diagnostics Guide (September 2018)
Automation tools: making things go... (March 2019)
Ad

Similar to Integrating SLF4J and the new OSGi LogService 1.4 - BJ Hargrave (IBM) (20)

PDF
Logging Application Behavior to MongoDB
PDF
Logging in Scala
PPT
PPTX
Java Logging
PDF
Dallas Mulesoft Meetup - Log Aggregation and Elastic Stack on Anypoint Platform
PPTX
What will be new in Apache NiFi 1.2.0
PPT
PDF
Cloud Foundry Logging and Metrics
PPTX
Elk ruminating on logs
PDF
What's new in the OSGi Enterprise Release 5.0
PPTX
Utilizing the OpenNTF Domino API
PDF
Oracle WebLogic Diagnostics & Perfomance tuning
PPTX
Log4j is a reliable, fast and flexible
PPTX
Python and GIS: Improving Your Workflow
PPT
Logging Services for .net - log4net
PDF
OSGi on Google Android using Apache Felix
PDF
ITB2024 - Keynote Day 1 - Ortus Solutions.pdf
PDF
Getting Started with BoxLang - CFCamp 2025.pdf
PDF
OSGi Community Event 2010 - OSGi Technical Update
PDF
FireBug And FirePHP
Logging Application Behavior to MongoDB
Logging in Scala
Java Logging
Dallas Mulesoft Meetup - Log Aggregation and Elastic Stack on Anypoint Platform
What will be new in Apache NiFi 1.2.0
Cloud Foundry Logging and Metrics
Elk ruminating on logs
What's new in the OSGi Enterprise Release 5.0
Utilizing the OpenNTF Domino API
Oracle WebLogic Diagnostics & Perfomance tuning
Log4j is a reliable, fast and flexible
Python and GIS: Improving Your Workflow
Logging Services for .net - log4net
OSGi on Google Android using Apache Felix
ITB2024 - Keynote Day 1 - Ortus Solutions.pdf
Getting Started with BoxLang - CFCamp 2025.pdf
OSGi Community Event 2010 - OSGi Technical Update
FireBug And FirePHP
Ad

More from mfrancis (20)

PDF
Eclipse Modeling Framework and plain OSGi the easy way - Mark Hoffman (Data I...
PDF
OSGi and Java 9+ - BJ Hargrave (IBM)
PDF
Simplify Web UX Coding using OSGi Modularity Magic - Paul Fraser (A2Z Living)
PDF
OSGi for the data centre - Connecting OSGi to Kubernetes - Frank Lyaruu
PDF
Remote Management and Monitoring of Distributed OSGi Applications - Tim Verbe...
PDF
OSGi with Docker - a powerful way to develop Java systems - Udo Hafermann (So...
PDF
A real world use case with OSGi R7 - Jurgen Albert (Data In Motion Consulting...
PDF
OSGi Feature Model - Where Art Thou - David Bosschaert (Adobe)
PDF
Migrating from PDE to Bndtools in Practice - Amit Kumar Mondal (Deutsche Tele...
PDF
OSGi CDI Integration Specification - Ray Augé (Liferay)
PDF
How OSGi drives cross-sector energy management - Jörn Tümmler (SMA Solar Tech...
PDF
Improved developer productivity thanks to Maven and OSGi - Lukasz Dywicki (Co...
PDF
It Was Twenty Years Ago Today - Building an OSGi based Smart Home System - Ch...
PDF
Popular patterns revisited on OSGi - Christian Schneider (Adobe)
PDF
OSG(a)i: because AI needs a runtime - Tim Verbelen (imec)
PDF
Flying to Jupiter with OSGi - Tony Walsh (ESA) & Hristo Indzhov (Telespazio V...
PDF
MicroProfile, OSGi was meant for this - Ray Auge (Liferay)
PDF
Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...
PDF
How to connect your OSGi application - Dirk Fauth (Bosch)
PDF
Visualization of OSGi based Software Architectures in Virtual Reality - Lisa ...
Eclipse Modeling Framework and plain OSGi the easy way - Mark Hoffman (Data I...
OSGi and Java 9+ - BJ Hargrave (IBM)
Simplify Web UX Coding using OSGi Modularity Magic - Paul Fraser (A2Z Living)
OSGi for the data centre - Connecting OSGi to Kubernetes - Frank Lyaruu
Remote Management and Monitoring of Distributed OSGi Applications - Tim Verbe...
OSGi with Docker - a powerful way to develop Java systems - Udo Hafermann (So...
A real world use case with OSGi R7 - Jurgen Albert (Data In Motion Consulting...
OSGi Feature Model - Where Art Thou - David Bosschaert (Adobe)
Migrating from PDE to Bndtools in Practice - Amit Kumar Mondal (Deutsche Tele...
OSGi CDI Integration Specification - Ray Augé (Liferay)
How OSGi drives cross-sector energy management - Jörn Tümmler (SMA Solar Tech...
Improved developer productivity thanks to Maven and OSGi - Lukasz Dywicki (Co...
It Was Twenty Years Ago Today - Building an OSGi based Smart Home System - Ch...
Popular patterns revisited on OSGi - Christian Schneider (Adobe)
OSG(a)i: because AI needs a runtime - Tim Verbelen (imec)
Flying to Jupiter with OSGi - Tony Walsh (ESA) & Hristo Indzhov (Telespazio V...
MicroProfile, OSGi was meant for this - Ray Auge (Liferay)
Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...
How to connect your OSGi application - Dirk Fauth (Bosch)
Visualization of OSGi based Software Architectures in Virtual Reality - Lisa ...

Recently uploaded (20)

PPTX
Big Data Technologies - Introduction.pptx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPT
Teaching material agriculture food technology
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
Cloud computing and distributed systems.
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Machine learning based COVID-19 study performance prediction
Big Data Technologies - Introduction.pptx
NewMind AI Weekly Chronicles - August'25 Week I
Understanding_Digital_Forensics_Presentation.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation
Network Security Unit 5.pdf for BCA BBA.
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
NewMind AI Monthly Chronicles - July 2025
Advanced methodologies resolving dimensionality complications for autism neur...
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Teaching material agriculture food technology
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Cloud computing and distributed systems.
Diabetes mellitus diagnosis method based random forest with bat algorithm
20250228 LYD VKU AI Blended-Learning.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Chapter 3 Spatial Domain Image Processing.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Machine learning based COVID-19 study performance prediction

Integrating SLF4J and the new OSGi LogService 1.4 - BJ Hargrave (IBM)

  • 1. The new OSGi LogService 1.4 and integrating with SLF4J BJ Hargrave, IBM
  • 2. Log Service • An OSGi specification for logging • Introduced in Release 1 in 2000 as an OSGi logging API • Many other OSGi spec require logging to the Log Service, for example DS • Pre-whiteboard; pre-log4j/slf4j • Versions 1.1, 1.2 and 1.3 only made fairly minor updates • Version 1.4 is a MAJOR update to the API inspired by SLF4J.
  • 4. Logger • An interface that allows a bundle to log information, including a message, a level, an exception, and a ServiceReference object • Named, typically the name of the class which will log to it • Associated with the bundle which creates the Logger • Provides log level specific methods to avoid message formatting work if the log level is not in effect • ‘{}’ message placeholders as well as support for java.util.Formatter placeholders: %s, %d, …
  • 6. Log Levels • Six log levels are defined Log Level Description AUDIT Always logged ERROR Error occurred WARN Non-blocking failure or unwanted event INFO Normal operation DEBUG Detailed output useful for developers TRACE High volume output for tracing purposes
  • 7. Logger Factory • OSGi service which is used to obtain Logger objects • LogService now extends LoggerFactory • LogService members deprecated • Logger names form a hierarchy using Java package.Class naming style • Special Logger named ROOT is the ancestor of all Loggers • Logger name hierarchy is used to manage Logger configuration
  • 8. Logger Configuration • The Logger Admin service is used to configure Logger Context objects • Each bundle can have a Logger Context object which can control the Log Levels for the Logger objects of that bundle • Map<String,LogLevel> com.foo.Bar=INFO com.foo=DEBUG com=INFO ROOT=ERROR
  • 9. Logger Configuration • There is also an unnamed “root” Logger Context from which all named Logger Contexts inherit configuration • Most people will just need to configure this Logger Context • Configuration Admin can be used to configure LoggerContexts using PIDs starting with “org.osgi.service.log.admin” • PID “org.osgi.service.log.admin” configures the “root” Logger Context • PID “org.osgi.service.log.admin|<bundle-symbolic-name>” configures the Logger Context for the bundle
  • 10. Where does logged information go? • The OSGi Log Service specification does not say anything about writing logged information to the console, files, etc. • This would be done by using the Log Reader Service or the new Log Stream Provider service • So the Log Service specification is “broker” between bundles wanting to log and bundles wanting to consume the logged information • Such a consuming bundle can be thought of like Appenders in other logging back ends such as Logback
  • 11. Log Stream Provider • Logged information can be thought of as an ongoing stream of log entries that never ends having asynchronous arrival • This fits perfectly with the new OSGi Push Stream specification! • So we added a new Log Stream Provider service which can be uses by a consuming bundle to receive and process log entries as a push stream • The push stream can be primed with the log history, if any, which is put in the stream ahead of any new entries
  • 12. Log Reader Service still remains • Even though the design of the Log Reader Service predates the advent of the whiteboard pattern, it remains supported in the specification • Existing code may use it • This also allows the Log Stream Provider implementation to be separate from the Log Service implementation • Which is handy for Equinox which implements the Log Service specification in the framework and was not quite ready to require Java 8 (which Push Stream requires)
  • 13. Log Entry expanded to hold new information • Logged information is packaged and delivered as a Log Entry object • With the new support for named Loggers, we enhanced Log Entry to provide more information • name of the Logger • a sequence number which orders log entries • thread and stack trace information about the logging call site
  • 14. Declarative Services support for using Loggers • DS will support creating and injecting a Logger for the component implementation class • If the reference is to the Logger Factory service and the injection target is Logger for Formatting Logger, then SCR must use the Logger Factory to create a Logger which is then injected @Component public class ExampleImpl implements Example { @Reference(service=LoggerFactory.class) // LoggerFactory.getLogger(ExampleImpl.class) private Logger logger; @Activate void activate() { logger.info("initialized"); } }
  • 15. But lots of projects use SLF4J?
  • 16. Lots of projects use SLF4J as their logging API • When you build an OSGi system, you will probably use a number of bundles from open source projects that log using SLF4J • And you will probably use a number of OSGi specification implementations which log using OSGi Log Service • So now you have a mix of bundles using different logging APIs and you need to the logging combined into a single stream • How to make the twain meet?
  • 17. Choices • We can either send the information logged to the OSGi Log Service to the SLF4J logging backend (e.g. Logback) • This means all the logged information is controlled by SLF4J logging backend configuration • Or we can send the information logged to the SLF4J API to the OSGi Log Service • This means all the logged information is controlled by the Logger configuration in the Logger Admin service
  • 18. slf4j.osgi • SLF4J implementation which maps using the SLF4J API, which is a static API, onto the OSGi Log Service • CODE!
  • 19. osgi.logback • Component which consumes Log Entries and sends them to the Logback backend • CODE!
  • 20. osgi.logback • See the Apache Felix Logback project for a more capable implementation of this choice • http://felix.apache.org/documentation/subprojects/apache-felix-logback.html
  • 21. Some notes… • We are using Equinox framework with its in-built Log Service implementation • So we need configure a log history so our bundles can find past logged information when they start • And we need to configure the Loggers so we have some logged information to process! • -runproperties: 
 equinox.log.history.max=1000,
 org.osgi.service.log.admin.loglevel=DEBUG
  • 23. Evaluate the Sessions -1 0 +1 Sign in and vote at eclipsecon.org