SlideShare ist ein Scribd-Unternehmen logo
1 von 23
Downloaden Sie, um offline zu lesen
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.
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, …
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

Weitere ähnliche Inhalte

Was ist angesagt?

Distributed OSGi Services with the Eclipse Communication Framework - Jan Rell...
Distributed OSGi Services with the Eclipse Communication Framework - Jan Rell...Distributed OSGi Services with the Eclipse Communication Framework - Jan Rell...
Distributed OSGi Services with the Eclipse Communication Framework - Jan Rell...
mfrancis
 

Was ist angesagt? (17)

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

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

Logging Services for .net - log4net
Logging Services for .net - log4netLogging Services for .net - log4net
Logging Services for .net - log4net
Guo Albert
 

Ähnlich wie Integrating SLF4J and the new OSGi LogService 1.4 - BJ Hargrave (IBM) (20)

Logging Application Behavior to MongoDB
Logging Application Behavior to MongoDBLogging Application Behavior to MongoDB
Logging Application Behavior to MongoDB
 
Logging in Scala
Logging in ScalaLogging in Scala
Logging in Scala
 
Log4e
Log4eLog4e
Log4e
 
Java Logging
Java LoggingJava Logging
Java Logging
 
Dallas Mulesoft Meetup - Log Aggregation and Elastic Stack on Anypoint Platform
Dallas Mulesoft Meetup - Log Aggregation and Elastic Stack on Anypoint PlatformDallas Mulesoft Meetup - Log Aggregation and Elastic Stack on Anypoint Platform
Dallas Mulesoft Meetup - Log Aggregation and Elastic Stack on Anypoint Platform
 
What will be new in Apache NiFi 1.2.0
What will be new in Apache NiFi 1.2.0What will be new in Apache NiFi 1.2.0
What will be new in Apache NiFi 1.2.0
 
Logback
LogbackLogback
Logback
 
Cloud Foundry Logging and Metrics
Cloud Foundry Logging and MetricsCloud Foundry Logging and Metrics
Cloud Foundry Logging and Metrics
 
Elk ruminating on logs
Elk ruminating on logsElk ruminating on logs
Elk ruminating on logs
 
What's new in the OSGi Enterprise Release 5.0
What's new in the OSGi Enterprise Release 5.0What's new in the OSGi Enterprise Release 5.0
What's new in the OSGi Enterprise Release 5.0
 
Utilizing the OpenNTF Domino API
Utilizing the OpenNTF Domino APIUtilizing the OpenNTF Domino API
Utilizing the OpenNTF Domino API
 
Oracle WebLogic Diagnostics & Perfomance tuning
Oracle WebLogic Diagnostics & Perfomance tuningOracle WebLogic Diagnostics & Perfomance tuning
Oracle WebLogic Diagnostics & Perfomance tuning
 
Log4j is a reliable, fast and flexible
Log4j is a reliable, fast and flexibleLog4j is a reliable, fast and flexible
Log4j is a reliable, fast and flexible
 
Python and GIS: Improving Your Workflow
Python and GIS: Improving Your WorkflowPython and GIS: Improving Your Workflow
Python and GIS: Improving Your Workflow
 
Logging Services for .net - log4net
Logging Services for .net - log4netLogging Services for .net - log4net
Logging Services for .net - log4net
 
OSGi on Google Android using Apache Felix
OSGi on Google Android using Apache FelixOSGi on Google Android using Apache Felix
OSGi on Google Android using Apache Felix
 
OSGi Community Event 2010 - OSGi Technical Update
OSGi Community Event 2010 - OSGi Technical UpdateOSGi Community Event 2010 - OSGi Technical Update
OSGi Community Event 2010 - OSGi Technical Update
 
FireBug And FirePHP
FireBug And FirePHPFireBug And FirePHP
FireBug And FirePHP
 
From the Trenches: Effectively Scaling Your Cloud Infrastructure and Optimizi...
From the Trenches: Effectively Scaling Your Cloud Infrastructure and Optimizi...From the Trenches: Effectively Scaling Your Cloud Infrastructure and Optimizi...
From the Trenches: Effectively Scaling Your Cloud Infrastructure and Optimizi...
 
OSGi enRoute Unveiled - P Kriens
OSGi enRoute Unveiled - P KriensOSGi enRoute Unveiled - P Kriens
OSGi enRoute Unveiled - P Kriens
 

Mehr von mfrancis

Migrating from PDE to Bndtools in Practice - Amit Kumar Mondal (Deutsche Tele...
Migrating from PDE to Bndtools in Practice - Amit Kumar Mondal (Deutsche Tele...Migrating from PDE to Bndtools in Practice - Amit Kumar Mondal (Deutsche Tele...
Migrating from PDE to Bndtools in Practice - Amit Kumar Mondal (Deutsche Tele...
mfrancis
 
How OSGi drives cross-sector energy management - Jörn Tümmler (SMA Solar Tech...
How OSGi drives cross-sector energy management - Jörn Tümmler (SMA Solar Tech...How OSGi drives cross-sector energy management - Jörn Tümmler (SMA Solar Tech...
How OSGi drives cross-sector energy management - Jörn Tümmler (SMA Solar Tech...
mfrancis
 
Improved developer productivity thanks to Maven and OSGi - Lukasz Dywicki (Co...
Improved developer productivity thanks to Maven and OSGi - Lukasz Dywicki (Co...Improved developer productivity thanks to Maven and OSGi - Lukasz Dywicki (Co...
Improved developer productivity thanks to Maven and OSGi - Lukasz Dywicki (Co...
mfrancis
 
Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...
Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...
Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...
mfrancis
 
Visualization of OSGi based Software Architectures in Virtual Reality - Lisa ...
Visualization of OSGi based Software Architectures in Virtual Reality - Lisa ...Visualization of OSGi based Software Architectures in Virtual Reality - Lisa ...
Visualization of OSGi based Software Architectures in Virtual Reality - Lisa ...
mfrancis
 

Mehr von mfrancis (20)

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

Kürzlich hochgeladen

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Kürzlich hochgeladen (20)

EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 

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.
  • 3.
  • 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, …
  • 5.
  • 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