control logging felix log service

1,154 views
Skip to first unread message

peter....@openfokus.org

unread,
Apr 1, 2014, 4:40:37 PM4/1/14
to bndtool...@googlegroups.com
Hi
I am using the log service

 4|Active     |    1|Apache Felix Log Service (1.0.0)

and I would like to control the log level. Following http://felix.apache.org/documentation/subprojects/apache-felix-framework/apache-felix-framework-configuration-properties.html,

I created a config.properties file with the following entry:

n64% cat /home/p/kepler/osgi-action/conf/config.properties                                                │                                                                                                        
felix.log.level=0 

This should disable logging.

In my rundescriptor I have :

-runvm: -Dfelix.config.properties=file:/home/p/kepler/osgi-action/conf/config.properties

But I continue to get log messages:

...
[org.apache.felix.framework] ServiceEvent REGISTERED
[org.apache.felix.framework] FrameworkEvent PACKAGES REFRESHED
...

What's wrong with this ?
Thanks

Peter Kriens

unread,
Apr 2, 2014, 3:57:56 AM4/2/14
to bndtool...@googlegroups.com
This log level is Felix Framework specific. There is no way to control the log level of the log since most people misunderstand the log. The OSGi LogService is only a relay between log producers and log consumers. It is the task of the consumer to handle log levels, the OSGi Log Service only reports it. A very fine example is the Apache Felix Webconsole that allows you to limit the log entries by level.

The events in question are mandated by the OSGi specification. The Apache Felix log level is only controlling the log level of the Apache Felix framework.

Kind regards,

Peter Kriens

--
You received this message because you are subscribed to the Google Groups "bndtools-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bndtools-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

open fokus

unread,
Apr 2, 2014, 6:46:20 AM4/2/14
to bndtool...@googlegroups.com
Thanks Peter, I will have a look at the webconsole code to see how it's done.

I'd still like to understand how osgi-pros do logging.

Suppose I have these basic logging requirements:
- all bundles shall log to a common file and to the console
- I want to configure the logging level for each bundle ( including for events mandated by the OSGi spec ) with a properties file.
- I want to have appenders to control formatting, timestamps, etc

In a traditional java/C++/whatever project, this would be trivial. I'd use log4j ( or equivalent ) and setup a log4j.properties file in the classpath.
Each class would then call a method logger.debug/info/etc on a static private field, after getting a logger with a specific name.

What would be the functional equivalent way to do this in OSGi ( I mean equivalent from the user's - the java developer's - point of view ) ?

[PS: In the books I have studied so far ( Osgi in practice by Neil Bartlett and OSGi in Action by Hall et al ) there is mention of LogService and LogListener and I have succeeded in using these to get some console output, as shown in my previous question. But this is just a toy and I can't find any useful information on how logging is *used* in *practice*. Certainly, I am not going to roll my own RotateLogFileAppender. The OSGi in Action book covers debugging with eclipse and jdb but my favorite debugging tool is by far an easily configurable and adjustable logging framework.]




Ferry Huberts

unread,
Apr 2, 2014, 7:01:37 AM4/2/14
to bndtool...@googlegroups.com

On 02/04/14 12:46, open fokus wrote:
Thanks Peter, I will have a look at the webconsole code to see how it's done.

I'd still like to understand how osgi-pros do logging.

Suppose I have these basic logging requirements:
- all bundles shall log to a common file and to the console
- I want to configure the logging level for each bundle ( including for events mandated by the OSGi spec ) with a properties file.
- I want to have appenders to control formatting, timestamps, etc

In a traditional java/C++/whatever project, this would be trivial. I'd use log4j ( or equivalent ) and setup a log4j.properties file in the classpath.
Each class would then call a method logger.debug/info/etc on a static private field, after getting a logger with a specific name.

What would be the functional equivalent way to do this in OSGi ( I mean equivalent from the user's - the java developer's - point of view ) ?

[PS: In the books I have studied so far ( Osgi in practice by Neil Bartlett and OSGi in Action by Hall et al ) there is mention of LogService and LogListener and I have succeeded in using these to get some console output, as shown in my previous question. But this is just a toy and I can't find any useful information on how logging is *used* in *practice*. Certainly, I am not going to roll my own RotateLogFileAppender. The OSGi in Action book covers debugging with eclipse and jdb but my favorite debugging tool is by far an easily configurable and adjustable logging framework.]



I'm using apache sling in one of my applications.
See the sling site for examples.

(below is from my bndtools workspace/projects)

I have in -runrequirements:
    osgi.identity;filter:='(osgi.identity=org.apache.sling.commons.log)',\
    osgi.identity;filter:='(osgi.identity=org.apache.sling.commons.logservice)',\

And in the -runbundles:
    org.apache.sling.commons.log;version='[3.0.2,3.0.3)',\
    org.apache.sling.commons.logservice;version='[1.0.2,1.0.3)',\
    slf4j.api;version='[1.6.2,1.6.3)'

in -runproperties I have
    felix.fileinstall.dir=./conf,\
    felix.fileinstall.enableConfigSave=false,\
    felix.fileinstall.noInitialDelay=true,\
    felix.fileinstall.poll=5000,\


obviously you need to configure it, I'm using configadmin for that, fed by fileinstall.
the files I have are:
- org.apache.sling.commons.log.LogManager.cfg
- org.apache.sling.commons.log.LogManager.factory.config-debug.txt
- org.apache.sling.commons.log.LogManager.factory.writer-debug.txt




-- 
Ferry Huberts

Felix Meschberger

unread,
Apr 2, 2014, 7:23:33 AM4/2/14
to bndtool...@googlegroups.com
Hi

With my OSGi hat on, the LogService looks nice upfront. But in the guts of it, it has some nasty properties: For one, it is a service and service may or may not be present. Not the kind of thing you want to depend on when it comes to logging.

So, what we generally do, is to suggest to use one of those logging APIs (Sling is my background, so SLF4J it is) instead and for provisioning to make sure to offer whatever APIs you can afford to offer and funnel everything through a single implementation. Coming back to Sling: We offer slf4j, log4j, commons-logging, and OSGi LogService and everything is funneled through a single slf4j implementations (logback these days).

The only time we really use the OSGi LogService is in implementations of OSGi specifications itself (see the Apache Felix Configuration Admin or Declarative Services implementations for examples), where we don't want to hook consumers into some concrete logging API but want to leverage what most probably will be there in an OSGi framework.

Regards
Felix

open fokus

unread,
Apr 2, 2014, 9:42:40 AM4/2/14
to bndtool...@googlegroups.com
Hi Ferry, thanks for sharing, this works, except that I can't configure the service:

There are two issues:

1)
I'm getting these:

02.04.2014 15:31:12.563 *INFO* [FelixDispatchQueue] org.apache.felix.framework FrameworkEvent PACKAGES REFRESHED
[org.apache.felix.framework] FrameworkEvent PACKAGES REFRESHED

The second entry seems to come from somewhere else, since it is not formatted by slf4j. How can I get these messages send to the same logging service (commons ) as the rest ?

2) I get the *INFO* entry although I set the level to ERROR.

I am confused with the names of the config files, you were suggesting
 
- org.apache.sling.commons.log.LogManager.cfg
- org.apache.sling.commons.log.LogManager.factory.config-debug.txt
- org.apache.sling.commons.log.LogManager.factory.writer-debug.txt

The sling logging website https://sling.apache.org/documentation/development/logging.html says:

... are registered under the PIDs org.apache.sling.commons.log.LogManager.factory.writer and org.apache.sling.commons.log.LogManager.factory.config to receive configurations.

toegether with the rules for fileinstall https://felix.apache.org/site/apache-felix-file-install.html
I would have guessed something like this:

org.apache.sling.commons.log.LogManager.factory.writer-debug.cfg
org.apache.sling.commons.log.LogManager.factory.config-debug.cfg

And I would put this in the config-debug.cfg factory config:

org.apache.sling.commons.log.level=ERROR
org.apache.sling.commons.log.file="log"

The ERROR level is obviously not taken into account in neither solution ( the one you suggested and the one that I would deduce from the docs). Nor is there a "log" file created.

Could you share the contents of your conf files ?

Ferry Huberts

unread,
Apr 2, 2014, 10:09:56 AM4/2/14
to bndtool...@googlegroups.com

On 02/04/14 15:42, open fokus wrote:
Hi Ferry, thanks for sharing, this works, except that I can't configure the service:

There are two issues:

1)
I'm getting these:

02.04.2014 15:31:12.563 *INFO* [FelixDispatchQueue] org.apache.felix.framework FrameworkEvent PACKAGES REFRESHED
[org.apache.felix.framework] FrameworkEvent PACKAGES REFRESHED

The second entry seems to come from somewhere else, since it is not formatted by slf4j. How can I get these messages send to the same logging service (commons ) as the rest ?

2) I get the *INFO* entry although I set the level to ERROR.

I am confused with the names of the config files, you were suggesting
 
- org.apache.sling.commons.log.LogManager.cfg
- org.apache.sling.commons.log.LogManager.factory.config-debug.txt
- org.apache.sling.commons.log.LogManager.factory.writer-debug.txt

The sling logging website https://sling.apache.org/documentation/development/logging.html says:

... are registered under the PIDs org.apache.sling.commons.log.LogManager.factory.writer and org.apache.sling.commons.log.LogManager.factory.config to receive configurations.

toegether with the rules for fileinstall https://felix.apache.org/site/apache-felix-file-install.html
I would have guessed something like this:

org.apache.sling.commons.log.LogManager.factory.writer-debug.cfg
org.apache.sling.commons.log.LogManager.factory.config-debug.cfg

Yes, you're right.
Sorry, I picked those names from the source tree and forgot I had renamed the file so that debug logging is not generated by default.


It took me some time fiddling with the settings as well ;-)



And I would put this in the config-debug.cfg factory config:

org.apache.sling.commons.log.level=ERROR
org.apache.sling.commons.log.file="log"

The ERROR level is obviously not taken into account in neither solution ( the one you suggested and the one that I would deduce from the docs). Nor is there a "log" file created.

Could you share the contents of your conf files ?





org.apache.sling.commons.log.LogManager.cfg
# Sets the initial logging level of the root logger. This may be any of the
# defined logging levels DEBUG, INFO, WARN, ERROR and FATAL.
# Default: INFO
org.apache.sling.commons.log.level=WARN

# Sets the log file to which log messages are written. If this property is
# empty or missing, log messages are written to System.out.
# Default: undefined
org.apache.sling.commons.log.file=./log/myapp.log

# The number of rotated files to keep.
# Default: 5
org.apache.sling.commons.log.file.number=5

# Defines how the log file is rotated (by schedule or by size) and when to
# rotate. See the section Log File Rotation at
# http://sling.apache.org/documentation/development/logging.html for full
# details on log file rotation.
# Default: '.'yyyy-MM-dd
org.apache.sling.commons.log.file.size=10M

# The java.util.MessageFormat pattern to use for formatting log messages with
# the root logger. This is a java.util.MessageFormat pattern supporting up to
# six arguments:
#   {0} The timestamp of type java.util.Date,
#   {1} the log marker,
#   {2} the name of the current thread,
#   {3} the name of the logger,
#   {4} the debug level,
#   {5} the actual debug message
# If the log call includes a Throwable, the stacktrace is just appended to the
# message regardless of the pattern.
# Default: {0,date,dd.MM.yyyy HH:mm:ss.SSS} *{4}* [{2}] {3} {5}
org.apache.sling.commons.log.pattern={0,date,yyyyMMdd HH:mm:ss.SSS} *{4}* [{2}] {3} : {5}

# Enables the java.util.logging support.
# Default: n/a
org.apache.sling.commons.log.julenabled=true

# Path for the Logback config file which would be used to configure logging.
# If the path is not absolute then it would be resolved against Sling Home
# Default: n/a
#org.apache.sling.commons.log.configurationFile

# Boolean property to control packaging data support of Logback.
# See [Packaging Data][11] section of Logback for more details
# Default: true
#org.apache.sling.commons.log.packagingDataEnabled


org.apache.sling.commons.log.LogManager.factory.config-debug.txt
# Sets the logging level of the loggers. This may be any of the defined logging
# levels DEBUG, INFO, WARN, ERROR and FATAL.
# Default: INFO
org.apache.sling.commons.log.level=DEBUG

# Sets the log file to which log messages are written. If this property is
# empty or missing, log messages are written to System.out. This property
# should refer to the file name of a configured Log Writer. If no Log Writer is
# configured with the same file name an implicit Log Writer configuration with
# default configuration is created.
# Default: undefined
org.apache.sling.commons.log.file=./log/myapp-debug.log

# The java.util.MessageFormat pattern to use for formatting log messages with
# the root logger. This is a java.util.MessageFormat pattern supporting up to
# six arguments:
#   {0} The timestamp of type java.util.Date,
#   {1} the log marker,
#   {2} the name of the current thread,
#   {3} the name of the logger,
#   {4} the debug level,
#   {5} the actual debug message
# If the log call includes a Throwable, the stacktrace is just appended to the
# message regardless of the pattern.
# Default: {0,date,dd.MM.yyyy HH:mm:ss.SSS} *{4}* [{2}]() {3} {5}
org.apache.sling.commons.log.pattern={0,date,yyyyMMdd HH:mm:ss.SSS} *{4}* [{2}] {3} : {5}

# A list of logger names to which this configuration applies.
# Default: --
org.apache.sling.commons.log.names=nl.pelagic

org.apache.sling.commons.log.LogManager.factory.writer-debug.txt
# Sets the log file to which log messages are written. If this property is
# empty or missing, log messages are written to System.out.
# Default: undefined
org.apache.sling.commons.log.file=./log/myapp-debug.log

# The number of rotated files to keep.
# Default: 5
org.apache.sling.commons.log.file.number=5

# Defines how the log file is rotated (by schedule or by size) and when to
# rotate. See the section Log File Rotation at
# http://sling.apache.org/documentation/development/logging.html for full
# details on log file rotation.
# Default: '.'yyyy-MM-dd
org.apache.sling.commons.log.file.size=10M



peter....@openfokus.org

unread,
Apr 2, 2014, 11:28:19 AM4/2/14
to bndtool...@googlegroups.com
Ok, Thanks again Ferry, your config files show me that I correctly understood the instructions from the sling site.
However, I still can't influence the log level, and I give up for now and read some more books an osgi and try to vent my frustration (;-
Reply all
Reply to author
Forward
0 new messages