|Custom Log-Appender [message #548216]
||Wed, 21 July 2010 07:30
| Marco Dubacher
Registered: July 2010
In our project I would like to define a custom appender. We use slf4j together with logback for logging.
As the logback.jar is quite well hidden within the medic-bundle the logback classes are not directly visible to be able to create a custom logback appender.
Furthermore I would like to add my own custom appender via the serviceability.xml. However, I guess that my customer appender (stored in a applicatino specific osgi bundle) is not visible to the classloader which will load the logback appenders defined in the serviceability.xml.
Any hints how to implement and configure a custom log appender in virgo are highly appreciated.
[Updated on: Wed, 21 July 2010 07:49]
Report message to a moderator
|Re: Custom Log-Appender [message #548274 is a reply to message #548216]
||Wed, 21 July 2010 10:42
Registered: January 2010
First, two things:
1. Can you give yourself a name on the forum, so we can spot your entries more easily?
2. If this question is more suited to developers rather than users, you might consider putting the same question (and response) on the Virgo-Dev mailing-list.
There are some experts there who can help.
There is a (unit) test for custom appenders in the org.eclipse.virgo.medic repository, which you might like to look at.
DefaultOutputAppender and LocalizedOutputAppender are used by test class LogBackEventLoggerTests in project org.eclipse.virgo.medic.core
in (test) package org.eclipse.virgo.medic.eventlog.impl.logback. The xml used is in logback-test.xml in test/resources in the same project.
However, there are a number of other considerations for adding appenders in Virgo Kernel/Web Server.
First of all, the appenders are loaded by logback, which is deployed early on in the kernel region startup, which means that (a) the packages you use to build your appender must be imported form the same place that the medic bundle gets its packages. (Actually, it is the medic bundle that exports them, so this is reasonably easy to achieve.)
Secondly, since these packages are exported in the kernel region (and not to the user region) this means that the bundle with your appender definitions in them needs to be deployed in the kernel region.
Finally, if your appenders are 'static' and you want to guarantee them to be available from the very start, logback does the loading of appenders from its classpath and the appenders need to be on the bundle classpath of the medic bundle. Without modifying medic what you do is to put the appender code in a fragment bundle and define medic as the host fragment. The fragment bundle is then deployed by putting it in the kernel region launch list. This effectively makes it part of the kernel.
If you want to dynamically add your appender to logback (using the addAppender api on Logger) then there is no need to have a fragment bundle, just make sure that the appender is added when the appender bundle is started. In this last case, it is still necessary to put the appender code in the kernel launch list -- after the medic bundle.
Please can you report back on your experiences on Virgo Dev?
PS: I do not recommend trying to add the appender from a user region bundle, as this may have timing issues.
Steve Powell :-/
Powered by FUDForum
. Page generated in 0.01762 seconds