In this chapter, we will use the Apache Felix Log Service implementation as a logging service provider. The Felix Log Service provides a simple implementation of the required functionality. It holds the log entries in memory and notifies listeners.
Install it just like we did with previous bundles:
g! bundlelevel -i 1
g! deploy -s "Apache Felix Log Service"
Target resource(s):
-------------------
Apache Felix Log Service (1.0.0)
Deploying...done.
For memory usage considerations, the Log Service's default configuration instructs it not to keep debug messages in its history and to limit the history size to 100 entries.
This configuration can be changed by setting values to the following system properties:
org.apache.felix.log.maxSize:
The maximum number of entries in the log reader history. Set to -1
for infiniteorg.apache.felix.log.storeDebug:
Whether or not to store the debug messages in history.It is not recommended to set maxSize
to -1
for long-lived framework runs. The used memory will increase as components send log events until there's no memory left. Also, a large load of debug messages is to be expected.
To change this default configuration, edit the configuration file under conf/config.properties
of your Felix instance.
At the end of the file, I've added the following:
# # Apache Felix Log Service properties # org.apache.felix.log.maxSize=500 org.apache.felix.log.storeDebug=true
I've set the storeDebug
to true
because we're in development mode. Remember to change it back to false
later!
The Felix Log Service also adds a shell command to inspect the log entries. The log
command takes an optional integer parameter to limit the number of log entries displayed and another optional parameter for log-level filtering:
g! help log
log - display some matching log entries
scope: felix
parameters:
int maximum number of entries
String minimum log level [ debug | info | warn | error ]
log - display all matching log entries
scope: felix
parameters:
String minimum log level [ debug | info | warn | error ]
The log-level filter shows log entries with a level smaller or equal to that passed. For example, log info
will show entries with levels info (=3), warn (=2), and error (=1).
For example, having just installed the Log Service, by listing the logs, we find the service startup logs:
g! log 5 info
2010.09.22 15:27:57 INFO - Bundle: org.apache.felix.log -
BundleEvent STARTED
2010.09.22 15:27:57 INFO - Bundle: org.apache.felix.log -
[org.osgi.service.log.LogReaderService] - ServiceEvent REGISTERED
2010.09.22 15:27:57 INFO - Bundle: org.apache.felix.log -
[org.osgi.service.log.LogService] - ServiceEvent REGISTERED
Here we have set a limit to the number of entries to show (5) and we filtered for info severity logs previously.