Download - Service Logging
![Page 1: Service Logging](https://reader031.vdocument.in/reader031/viewer/2022020110/5552f4b1b4c90584028b4d17/html5/thumbnails/1.jpg)
Velossity@Training 2012-Services/Log/11
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]
![Page 2: Service Logging](https://reader031.vdocument.in/reader031/viewer/2022020110/5552f4b1b4c90584028b4d17/html5/thumbnails/2.jpg)
Velossity@Training 2012-Services/Log/12
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]
![Page 3: Service Logging](https://reader031.vdocument.in/reader031/viewer/2022020110/5552f4b1b4c90584028b4d17/html5/thumbnails/3.jpg)
Velossity@Training 2012-Services/Log/13
Architecture big picturecmp Big Picture
Back-endClient side
Logger
MyBundle
HttpSe rv ice
ConfigAdmin
ConsoleLog
Log2Tw itterLogReade rService
LogReade rService
LogSe rvice
LogSe rvice
LogSe rvice
LogListener
LogListener
![Page 4: Service Logging](https://reader031.vdocument.in/reader031/viewer/2022020110/5552f4b1b4c90584028b4d17/html5/thumbnails/4.jpg)
Velossity@Training 2012-Services/Log/14
Logging APIclass log
Back-endClient side
«interface»LogEntry
+ getBundle() : Bundle+ getException() : Throwable+ getLevel() : int+ getMessage() : String+ getServiceReference() : ServiceReference+ getTime() : long
EventListener
«interface»LogListener
+ logged(LogEntry) : void
«interface»LogReaderService
+ addLogListener(LogListener) : void+ getLog() : Enumeration+ removeLogListener(LogListener) : void
«interface»LogService
+ LOG_DEBUG: int = 4 {readOnly}+ LOG_ERROR: int = 1 {readOnly}+ LOG_INFO: int = 3 {readOnly}+ LOG_WARNING: int = 2 {readOnly}
+ log(int, String) : void+ log(int, String, Throwable) : void+ log(ServiceReference, int, String) : void+ log(ServiceReference, int, String, Throwable) : void
![Page 5: Service Logging](https://reader031.vdocument.in/reader031/viewer/2022020110/5552f4b1b4c90584028b4d17/html5/thumbnails/5.jpg)
Velossity@Training 2012-Services/Log/15
LogService interaction
sd Logging
Client
«service»
LogServiceImpl:LogService
«service»
LogReaderServiceImpl:LogReaderService
«interface»
MyListener:LogListener
log(int, String)
fireEvent(LogEntry)
addLogListener(LogListener)
log(int, String)
fireEvent(LogEntry)
logged(LogEntry)
![Page 6: Service Logging](https://reader031.vdocument.in/reader031/viewer/2022020110/5552f4b1b4c90584028b4d17/html5/thumbnails/6.jpg)
Velossity@Training 2012-Services/Log/16
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
![Page 7: Service Logging](https://reader031.vdocument.in/reader031/viewer/2022020110/5552f4b1b4c90584028b4d17/html5/thumbnails/7.jpg)
Velossity@Training 2012-Services/Log/17
Pax bridge
sd JCL
Pax BridgeCommons-API LogService
:LogFactory
Client
«interface»
JCLLogger :Log
«interface»
PaxLoggerImpl:PaxLogger
Log4jLogger:Logger
:PaxLoggingServiceImpl :LogReaderServiceImpl
getLog(Cl ass) :Log
info(Object)
inform(String, Throwable)
info(Object)
handleEvents(Bundle, ServiceReference, int, String, Throwable)
fireEvent(LogEntry)
![Page 8: Service Logging](https://reader031.vdocument.in/reader031/viewer/2022020110/5552f4b1b4c90584028b4d17/html5/thumbnails/8.jpg)
Velossity@Training 2012-Services/Log/18
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 logger
Basic back-end
Defines a Log command
![Page 9: Service Logging](https://reader031.vdocument.in/reader031/viewer/2022020110/5552f4b1b4c90584028b4d17/html5/thumbnails/9.jpg)
Velossity@Training 2012-Services/Log/19
Back-end configuration
Use Config Admin and FileInstall to manage dynamically log listeners
cmp Logging
LoggingServ ice
ConfigAdmin
etc/org.ops4j.p ax.logging.cfg
File Install
ManagedService [service.pi d = org.ops4j.pax.logging]
watching
Configura tionAdmin
![Page 10: Service Logging](https://reader031.vdocument.in/reader031/viewer/2022020110/5552f4b1b4c90584028b4d17/html5/thumbnails/10.jpg)
Velossity@Training 2012-Services/Log/110
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
![Page 11: Service Logging](https://reader031.vdocument.in/reader031/viewer/2022020110/5552f4b1b4c90584028b4d17/html5/thumbnails/11.jpg)
Velossity@Training 2012-Services/Log/111
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
![Page 12: Service Logging](https://reader031.vdocument.in/reader031/viewer/2022020110/5552f4b1b4c90584028b4d17/html5/thumbnails/12.jpg)
Velossity@Training 2012-Services/Log/112
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