Service Logging


Published on

OSGi Log Service Tutorial using Twitter as back-end

  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Service Logging

  1. 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. 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. 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 ConfigAdmin3 Velossity@Training 2012-Services/Log/1
  4. 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() : long4 Velossity@Training 2012-Services/Log/1
  5. 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. 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 service6 Velossity@Training 2012-Services/Log/1
  7. 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. 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 command8 Velossity@Training 2012-Services/Log/1
  9. 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.cfg9 Velossity@Training 2012-Services/Log/1
  10. 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 jars10 Velossity@Training 2012-Services/Log/1
  11. 11. References [1] OSGi logging: [2] Pax-Logging: [3] FileInstall: [4] Knopflerfish: Velossity@Training 2012-Services/Log/1
  12. 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* * Software Configuration Management: svn co Continuous Integration: Velossity@Training 2012-Services/Log/1