Integrating OSGi (Felix), Logback and SLF4J

I'm trying to integrate Logback Classic in Apache Felix. My goal is to have a bundle-based context system so each bundle has it's own logging factory. It's important that each bundle is able to supply it's own configuration file. I've tried a few things and even wrote a simple ContextSelector but I don't seem to get it right. Therefore I thought: before going in a time consuming trial and error process let's ask the experts first. So, my question: how can I create new loggercontexts efficiently with each a separate configuration? Regards, Sander

Sounds like what I did for android. How is code typically posted for this forum? On Jul 5, 2010 4:59 AM, "Sander de Groot" <s.degroot@jdi.nl> wrote: I'm trying to integrate Logback Classic in Apache Felix. My goal is to have a bundle-based context system so each bundle has it's own logging factory. It's important that each bundle is able to supply it's own configuration file. I've tried a few things and even wrote a simple ContextSelector but I don't seem to get it right. Therefore I thought: before going in a time consuming trial and error process let's ask the experts first. So, my question: how can I create new loggercontexts efficiently with each a separate configuration? Regards, Sander _______________________________________________ Logback-user mailing list Logback-user@qos.ch http://qos.ch/mailman/listinfo/logback-user

What did you do for android? I'm myself new to this list so I don't really know how it's typically done but I'd suggest to paste the code in here if its not too large and it is then post a link to it. On 07/05/2010 01:22 PM, Fred wrote:
Sounds like what I did for android. How is code typically posted for this forum?
On Jul 5, 2010 4:59 AM, "Sander de Groot" <s.degroot@jdi.nl <mailto:s.degroot@jdi.nl>> wrote:
I'm trying to integrate Logback Classic in Apache Felix. My goal is to have a bundle-based context system so each bundle has it's own logging factory. It's important that each bundle is able to supply it's own configuration file.
I've tried a few things and even wrote a simple ContextSelector but I don't seem to get it right. Therefore I thought: before going in a time consuming trial and error process let's ask the experts first.
So, my question: how can I create new loggercontexts efficiently with each a separate configuration?
Regards,
Sander _______________________________________________ Logback-user mailing list Logback-user@qos.ch <mailto:Logback-user@qos.ch> http://qos.ch/mailman/listinfo/logback-user
_______________________________________________ Logback-user mailing list Logback-user@qos.ch http://qos.ch/mailman/listinfo/logback-user

Hi Sander, ContextSelector is one way of demultiplexing events per bundle. Another way is through SiftingAppender (or GSiftingAppender its equivalent in Groovy) which might be more convenient to use. Regardless of whether you use ContextSelector or SiftingAppender/GSiftingAppender, you first need a way to distinguish events generated by different bundles. Is there a way to differentiate logging events generated by different bundles? [1] http://logback.qos.ch/manual/appenders.html#SiftingAppender On 05/07/2010 11:59 AM, Sander de Groot wrote:
I'm trying to integrate Logback Classic in Apache Felix. My goal is to have a bundle-based context system so each bundle has it's own logging factory. It's important that each bundle is able to supply it's own configuration file.
I've tried a few things and even wrote a simple ContextSelector but I don't seem to get it right. Therefore I thought: before going in a time consuming trial and error process let's ask the experts first.
So, my question: how can I create new loggercontexts efficiently with each a separate configuration?
Regards,
Sander

Ah i see. Maybe the SiftingAppender is even a better option! But even with the SiftingAppender the problem is the same, like you said I need a way to differentiate between bundles. I'd like to differentiate based on the bundle name (or symbolic name). I'd use the MDC discriminator but this is not an option since SLF4J is also shared between all bundles. It's not a problem if I need to do one or a few calls within each bundle for the logging to work correctly. The longer I think about it the more I think its easier to use multiple contexts. How should I continue? On 07/06/2010 09:52 AM, Ceki Gülcü wrote:
Hi Sander,
ContextSelector is one way of demultiplexing events per bundle. Another way is through SiftingAppender (or GSiftingAppender its equivalent in Groovy) which might be more convenient to use.
Regardless of whether you use ContextSelector or SiftingAppender/GSiftingAppender, you first need a way to distinguish events generated by different bundles. Is there a way to differentiate logging events generated by different bundles?
[1] http://logback.qos.ch/manual/appenders.html#SiftingAppender
On 05/07/2010 11:59 AM, Sander de Groot wrote:
I'm trying to integrate Logback Classic in Apache Felix. My goal is to have a bundle-based context system so each bundle has it's own logging factory. It's important that each bundle is able to supply it's own configuration file.
I've tried a few things and even wrote a simple ContextSelector but I don't seem to get it right. Therefore I thought: before going in a time consuming trial and error process let's ask the experts first.
So, my question: how can I create new loggercontexts efficiently with each a separate configuration?
Regards,
Sander
_______________________________________________ Logback-user mailing list Logback-user@qos.ch http://qos.ch/mailman/listinfo/logback-user

On 12/07/2010 4:49 PM, Sander de Groot wrote:
Ah i see. Maybe the SiftingAppender is even a better option! But even with the SiftingAppender the problem is the same, like you said I need a way to differentiate between bundles. I'd like to differentiate based on the bundle name (or symbolic name). I'd use the MDC discriminator but this is not an option since SLF4J is also shared between all bundles.
It's not a problem if I need to do one or a few calls within each bundle for the logging to work correctly. The longer I think about it the more I think its easier to use multiple contexts.
How should I continue?
I think you should concentrate on the code for distinguishing the bundles. I am fairly certain that distinguishing the bundles is the crux of the problem. Once that is done, you can choose between multiple contexts or SiftingAppender. I suggest you post some code for discussion. -- Ceki

I think you should concentrate on the code for distinguishing the bundles. I am fairly certain that distinguishing the bundles is the crux of the problem. Once that is done, you can choose between multiple contexts or SiftingAppender. I suggest you post some code for discussion. When I think of the best way to distinguish between bundles, I think of creating new logging contexts based on installing/uninstalling bundles. Perhaps it's best to create a new OSGi service which creates new logging contexts based on bundle ID's or bundle names.
But for this to work I need to be able to create multiple name-based contexts within logback. The following (simplified) architecture would form: Logback < SLF4J < Custom Logging Service < CustomBundle With the above architecture I'd be able to determine which bundle wants to log something and would also be able to have a specific configuration per bundle. However this will only work if I'm able to create multiple contexts, is there a way for me to do this? I greatly appreciate your replies. Regards, Sander
participants (3)
-
Ceki Gülcü
-
Fred
-
Sander de Groot