SlideShare a Scribd company logo
1 of 12
OSGi Logging: The basics

     Two parts in a logger: the client bundle who
     wants to log and the back-end to manage
     logs
      –   A very simple API for the client side
      –   The logging back-end, or how the log entries are
          displayed, stored, or processed is currently not
          defined by the OSGI specifications [1]



1                                             Velossity@Training 2012-Services/Log/1
Separation of concerns

     Application developers just choose when and
      what to log, with which log level
     Platform administrators choose how the log
      entries are displayed, stored, or processed
      –   logging strategy can be defined not only in terms
          of packages and classes, but also in terms of
          services and bundles [1]



2                                             Velossity@Training 2012-Services/Log/1
Architecture big picture
    cmp Big Picture


                                 Client side                                                 Back-end



                  MyBundle                                               LogReade rService
                                               LogSe rvice
                                                                                                        Conso leLog


                                           LogSe rvice       Logger                 LogListener

                                                                                   LogListener
                 HttpSe rv ice
                                          LogSe rvice



                                                                                                        Log2Tw itter
                                                                      LogReade rService

                ConfigAdmin




3                                                                                            Velossity@Training 2012-Services/Log/1
Logging API
    class log


                                   Client side                                         Back-end

                                «interface»
                                LogService
           +    LOG_DEBUG: int = 4 {readOnly}                                        «interface»
                                                                                  LogReaderService
           +    LOG_ERROR: int = 1 {readOnly}
           +    LOG_INFO: int = 3 {readOnly}                           +   addLogListener(LogListener) : void
           +    LOG_WARNING: int = 2 {readOnly}                        +   getLog() : Enumeration
                                                                       +   removeLogListener(LogListener) : void
           +    log(int, String) : void
           +    log(int, String, Throwable) : void
           +    log(ServiceReference, int, String) : void
           +    log(ServiceReference, int, String, Throwable) : void
                                                                                          EventListener
                                                                                    «interface»
                                 «interface»                                        LogListener
                                  LogEntry                                   +   logged(LogEntry) : void
                +   getBundle() : Bundle
                +   getException() : Throwable
                +   getLevel() : int
                +   getMessage() : String
                +   getServiceReference() : ServiceReference
                +   getTime() : long




4                                                                                     Velossity@Training 2012-Services/Log/1
LogService interaction
    sd Logging


                                          «service»                             «service»                                       «interface»
                                        LogServiceImpl                     LogReaderServiceImpl                                  MyListener
            Client                       :LogService                         :LogReaderService                                  :LogListener


                     log(int, String)


                                                         fireEvent(LogEntry)


                                                                                                  addLogListener(LogListener)


                     log(int, String)


                                                         fireEvent(LogEntry)


                                                                                                       logged(LogEntry)




5                                                                                                          Velossity@Training 2012-Services/Log/1
Alternative: The logging bridge

     The  easy way to log with OSGi is to use an
      “old java logging API” acting like a façade
     Such solution uses a LogService
      implementation as the back-end for the Log
      implementation
      –   Pros: compliant with Java world
      –   Cons: not easily swappable as your code don’t
          rely on the standard OSGi service

6                                            Velossity@Training 2012-Services/Log/1
Pax bridge

    sd JCL


                                                Commons-API                                                                              Pax Bridge                                                        LogService

                                             :LogFactory        «interface»                               «interface»                  Log4jLogger                 :PaxLoggingServiceImpl         :LogReaderServiceImpl
                                                              JCLLogger :Log                         PaxLoggerImpl                       :Logger
             Client                                                                                   :PaxLogger


                      getLog(Cl ass) :Log


                                            info(Object)


                                                                              inform(String, Throwable)


                                                                                                                        info(Object)


                                                                                                                               handleEvents(Bundle, ServiceReference, int, String, Throwable)


                                                                                                                                                                                     fireEvent(LogEntry)




7                                                                                                                                                           Velossity@Training 2012-Services/Log/1
JCL open implementations

    Pax Logging    Compliant with most popular logger APIs
                   (JCL, sl4j,JDK logging, …)
                   Uses Log4j as back-end
                   Easily and dynamically configurable
    Knopflerfish   Basic back-end
    logger         Defines a Log command




8                                           Velossity@Training 2012-Services/Log/1
Back-end configuration
     UseConfig Admin and FileInstall to manage
     dynamically log listeners
        cmp Logging

                                             Configura tionAdmin
                          File Install                                   ConfigAdmin




                                                      ManagedService [service.pi d = org.ops4j.pax.logging]

                  watching




                                                                        LoggingServ ice

            etc/org.ops4j.p ax.logging.cfg




9                                                                                         Velossity@Training 2012-Services/Log/1
Recommendations

      Choose   one API for all your clients
      Define clearly the log levels
      Bind to the Logging Service only if using
       Dynamic frameworks
      Ensure that log4j.jar, commons-logging.jar, and
       any other legacy API that you want to use, are
       NOT included in your bundle jars


10                                        Velossity@Training 2012-Services/Log/1
References
     [1] OSGi logging: http://code.google.com/p/osgi-logging/
     [2] Pax-Logging: http://www.ops4j.org/projects/pax/logging/
     [3] FileInstall: http://felix.apache.org/site/apache-felix-file-install.html
     [4] Knopflerfish:
         http://www.knopflerfish.org/releases/3.1.0/docs/bundledoc/log/index.html




11                                                                  Velossity@Training 2012-Services/Log/1
Maven multi-modules organization
     | aggregator                                   -- Run multi-modules build
     | parent                                      -- Parent of all modules
     | JCL                                         -- Logging with JCL API
     | ServiceBinding                             -- Logging with LogService API
     | Log2Twitter                                -- Logging back-end sending direct messages to Twitter
     | TwitterService                             -- OSGi wrapper relying on Twitter4J*




     *http://twitter4j.org/en/index.html



         Software Configuration Management:
         svn co https://osgipatterns.svn.sourceforge.net/svnroot/osgipatterns/services/logging/tags/logging.aggregator-1.0.1

         Continuous Integration:
         http://velossity.zapto.org:8080/job/Logging/modules




12                                                                                              Velossity@Training 2012-Services/Log/1

More Related Content

Similar to Service Logging

Rein_in_the_ability_of_log4j
Rein_in_the_ability_of_log4jRein_in_the_ability_of_log4j
Rein_in_the_ability_of_log4jRazorsight
 
Integrating SLF4J and the new OSGi LogService 1.4 - BJ Hargrave (IBM)
Integrating SLF4J and the new OSGi LogService 1.4 - BJ Hargrave (IBM)Integrating SLF4J and the new OSGi LogService 1.4 - BJ Hargrave (IBM)
Integrating SLF4J and the new OSGi LogService 1.4 - BJ Hargrave (IBM)mfrancis
 
The new OSGi LogService 1.4 and integrating with SLF4J
The new OSGi LogService 1.4 and integrating with SLF4JThe new OSGi LogService 1.4 and integrating with SLF4J
The new OSGi LogService 1.4 and integrating with SLF4Jbjhargrave
 
OSGi Service Platform 4.2
OSGi Service Platform 4.2OSGi Service Platform 4.2
OSGi Service Platform 4.2Ilya Katsov
 
Deep Dive into SpaceONE
Deep Dive into SpaceONEDeep Dive into SpaceONE
Deep Dive into SpaceONEChoonho Son
 
Wso2 esb-maintenance-guide
Wso2 esb-maintenance-guideWso2 esb-maintenance-guide
Wso2 esb-maintenance-guideChanaka Fernando
 
Security threat analysis points for enterprise with oss
Security threat analysis points for enterprise with ossSecurity threat analysis points for enterprise with oss
Security threat analysis points for enterprise with ossHibino Hisashi
 
Logging using ELK Stack for Microservices
Logging using ELK Stack for MicroservicesLogging using ELK Stack for Microservices
Logging using ELK Stack for MicroservicesVineet Sabharwal
 
Logging & Metrics with Docker
Logging & Metrics with DockerLogging & Metrics with Docker
Logging & Metrics with DockerStefan Zier
 
Logging, Serilog, Structured Logging, Seq
Logging, Serilog, Structured Logging, SeqLogging, Serilog, Structured Logging, Seq
Logging, Serilog, Structured Logging, SeqDoruk Uluçay
 
Log Management Systems
Log Management SystemsLog Management Systems
Log Management SystemsMehdi Hamidi
 
Manage software dependencies with ioc and aop
Manage software dependencies with ioc and aopManage software dependencies with ioc and aop
Manage software dependencies with ioc and aopStefano Leli
 
Eclipse Training - Main eclipse ecosystem classes
Eclipse Training - Main eclipse ecosystem classesEclipse Training - Main eclipse ecosystem classes
Eclipse Training - Main eclipse ecosystem classesLuca D'Onofrio
 
MuleSoft Surat Virtual Meetup#7 - JSON Logger and Common Error Handling With ...
MuleSoft Surat Virtual Meetup#7 - JSON Logger and Common Error Handling With ...MuleSoft Surat Virtual Meetup#7 - JSON Logger and Common Error Handling With ...
MuleSoft Surat Virtual Meetup#7 - JSON Logger and Common Error Handling With ...Jitendra Bafna
 
OSDC 2014: Jordan Sissel - Find Happiness in your Logs
 OSDC 2014: Jordan Sissel - Find Happiness in your Logs OSDC 2014: Jordan Sissel - Find Happiness in your Logs
OSDC 2014: Jordan Sissel - Find Happiness in your LogsNETWAYS
 
Loggly - Tools and Techniques For Logging Microservices
Loggly - Tools and Techniques For Logging MicroservicesLoggly - Tools and Techniques For Logging Microservices
Loggly - Tools and Techniques For Logging MicroservicesSolarWinds Loggly
 

Similar to Service Logging (20)

OSGi bootcamp - part 2
OSGi bootcamp - part 2OSGi bootcamp - part 2
OSGi bootcamp - part 2
 
Rein_in_the_ability_of_log4j
Rein_in_the_ability_of_log4jRein_in_the_ability_of_log4j
Rein_in_the_ability_of_log4j
 
Integrating SLF4J and the new OSGi LogService 1.4 - BJ Hargrave (IBM)
Integrating SLF4J and the new OSGi LogService 1.4 - BJ Hargrave (IBM)Integrating SLF4J and the new OSGi LogService 1.4 - BJ Hargrave (IBM)
Integrating SLF4J and the new OSGi LogService 1.4 - BJ Hargrave (IBM)
 
The new OSGi LogService 1.4 and integrating with SLF4J
The new OSGi LogService 1.4 and integrating with SLF4JThe new OSGi LogService 1.4 and integrating with SLF4J
The new OSGi LogService 1.4 and integrating with SLF4J
 
OSGi Service Platform 4.2
OSGi Service Platform 4.2OSGi Service Platform 4.2
OSGi Service Platform 4.2
 
Logback
LogbackLogback
Logback
 
Deep Dive into SpaceONE
Deep Dive into SpaceONEDeep Dive into SpaceONE
Deep Dive into SpaceONE
 
Wso2 esb-maintenance-guide
Wso2 esb-maintenance-guideWso2 esb-maintenance-guide
Wso2 esb-maintenance-guide
 
Security threat analysis points for enterprise with oss
Security threat analysis points for enterprise with ossSecurity threat analysis points for enterprise with oss
Security threat analysis points for enterprise with oss
 
Logging using ELK Stack for Microservices
Logging using ELK Stack for MicroservicesLogging using ELK Stack for Microservices
Logging using ELK Stack for Microservices
 
Logging & Metrics with Docker
Logging & Metrics with DockerLogging & Metrics with Docker
Logging & Metrics with Docker
 
The future of C#
The future of C#The future of C#
The future of C#
 
Logging, Serilog, Structured Logging, Seq
Logging, Serilog, Structured Logging, SeqLogging, Serilog, Structured Logging, Seq
Logging, Serilog, Structured Logging, Seq
 
Log Management Systems
Log Management SystemsLog Management Systems
Log Management Systems
 
Hybrid Applications
Hybrid ApplicationsHybrid Applications
Hybrid Applications
 
Manage software dependencies with ioc and aop
Manage software dependencies with ioc and aopManage software dependencies with ioc and aop
Manage software dependencies with ioc and aop
 
Eclipse Training - Main eclipse ecosystem classes
Eclipse Training - Main eclipse ecosystem classesEclipse Training - Main eclipse ecosystem classes
Eclipse Training - Main eclipse ecosystem classes
 
MuleSoft Surat Virtual Meetup#7 - JSON Logger and Common Error Handling With ...
MuleSoft Surat Virtual Meetup#7 - JSON Logger and Common Error Handling With ...MuleSoft Surat Virtual Meetup#7 - JSON Logger and Common Error Handling With ...
MuleSoft Surat Virtual Meetup#7 - JSON Logger and Common Error Handling With ...
 
OSDC 2014: Jordan Sissel - Find Happiness in your Logs
 OSDC 2014: Jordan Sissel - Find Happiness in your Logs OSDC 2014: Jordan Sissel - Find Happiness in your Logs
OSDC 2014: Jordan Sissel - Find Happiness in your Logs
 
Loggly - Tools and Techniques For Logging Microservices
Loggly - Tools and Techniques For Logging MicroservicesLoggly - Tools and Techniques For Logging Microservices
Loggly - Tools and Techniques For Logging Microservices
 

Service Logging

  • 1. OSGi Logging: The basics  Two parts in a logger: the client bundle who wants to log and the back-end to manage logs – A very simple API for the client side – The logging back-end, or how the log entries are displayed, stored, or processed is currently not defined by the OSGI specifications [1] 1 Velossity@Training 2012-Services/Log/1
  • 2. Separation of concerns  Application developers just choose when and what to log, with which log level  Platform administrators choose how the log entries are displayed, stored, or processed – logging strategy can be defined not only in terms of packages and classes, but also in terms of services and bundles [1] 2 Velossity@Training 2012-Services/Log/1
  • 3. Architecture big picture cmp Big Picture Client side Back-end MyBundle LogReade rService LogSe rvice Conso leLog LogSe rvice Logger LogListener LogListener HttpSe rv ice LogSe rvice Log2Tw itter LogReade rService ConfigAdmin 3 Velossity@Training 2012-Services/Log/1
  • 4. Logging API class log Client side Back-end «interface» LogService + LOG_DEBUG: int = 4 {readOnly} «interface» LogReaderService + LOG_ERROR: int = 1 {readOnly} + LOG_INFO: int = 3 {readOnly} + addLogListener(LogListener) : void + LOG_WARNING: int = 2 {readOnly} + getLog() : Enumeration + removeLogListener(LogListener) : void + log(int, String) : void + log(int, String, Throwable) : void + log(ServiceReference, int, String) : void + log(ServiceReference, int, String, Throwable) : void EventListener «interface» «interface» LogListener LogEntry + logged(LogEntry) : void + getBundle() : Bundle + getException() : Throwable + getLevel() : int + getMessage() : String + getServiceReference() : ServiceReference + getTime() : long 4 Velossity@Training 2012-Services/Log/1
  • 5. LogService interaction sd Logging «service» «service» «interface» LogServiceImpl LogReaderServiceImpl MyListener Client :LogService :LogReaderService :LogListener log(int, String) fireEvent(LogEntry) addLogListener(LogListener) log(int, String) fireEvent(LogEntry) logged(LogEntry) 5 Velossity@Training 2012-Services/Log/1
  • 6. Alternative: The logging bridge  The easy way to log with OSGi is to use an “old java logging API” acting like a façade  Such solution uses a LogService implementation as the back-end for the Log implementation – Pros: compliant with Java world – Cons: not easily swappable as your code don’t rely on the standard OSGi service 6 Velossity@Training 2012-Services/Log/1
  • 7. Pax bridge sd JCL Commons-API Pax Bridge LogService :LogFactory «interface» «interface» Log4jLogger :PaxLoggingServiceImpl :LogReaderServiceImpl JCLLogger :Log PaxLoggerImpl :Logger Client :PaxLogger getLog(Cl ass) :Log info(Object) inform(String, Throwable) info(Object) handleEvents(Bundle, ServiceReference, int, String, Throwable) fireEvent(LogEntry) 7 Velossity@Training 2012-Services/Log/1
  • 8. JCL open implementations Pax Logging Compliant with most popular logger APIs (JCL, sl4j,JDK logging, …) Uses Log4j as back-end Easily and dynamically configurable Knopflerfish Basic back-end logger Defines a Log command 8 Velossity@Training 2012-Services/Log/1
  • 9. Back-end configuration  UseConfig Admin and FileInstall to manage dynamically log listeners cmp Logging Configura tionAdmin File Install ConfigAdmin ManagedService [service.pi d = org.ops4j.pax.logging] watching LoggingServ ice etc/org.ops4j.p ax.logging.cfg 9 Velossity@Training 2012-Services/Log/1
  • 10. Recommendations  Choose one API for all your clients  Define clearly the log levels  Bind to the Logging Service only if using Dynamic frameworks  Ensure that log4j.jar, commons-logging.jar, and any other legacy API that you want to use, are NOT included in your bundle jars 10 Velossity@Training 2012-Services/Log/1
  • 11. References [1] OSGi logging: http://code.google.com/p/osgi-logging/ [2] Pax-Logging: http://www.ops4j.org/projects/pax/logging/ [3] FileInstall: http://felix.apache.org/site/apache-felix-file-install.html [4] Knopflerfish: http://www.knopflerfish.org/releases/3.1.0/docs/bundledoc/log/index.html 11 Velossity@Training 2012-Services/Log/1
  • 12. Maven multi-modules organization | aggregator -- Run multi-modules build | parent -- Parent of all modules | JCL -- Logging with JCL API | ServiceBinding -- Logging with LogService API | Log2Twitter -- Logging back-end sending direct messages to Twitter | TwitterService -- OSGi wrapper relying on Twitter4J* *http://twitter4j.org/en/index.html Software Configuration Management: svn co https://osgipatterns.svn.sourceforge.net/svnroot/osgipatterns/services/logging/tags/logging.aggregator-1.0.1 Continuous Integration: http://velossity.zapto.org:8080/job/Logging/modules 12 Velossity@Training 2012-Services/Log/1