Skip to main content



      Home
Home » Eclipse Projects » Virgo » Logging the bundle name
Logging the bundle name [message #644919] Tue, 14 December 2010 13:18 Go to next message
Eclipse UserFriend
Is there something I can add to the logback pattern layout to log the bundle name?

Background: I have a shared class that is instantiated as a bean within the Spring contexts of several bundles. When this bean logs an Exception it is unclear as to which bundle the exception occurred within. The ideal approach would be to have the logging system tell me this automatically rather than adding information to the log message manually.
Re: Logging the bundle name [message #645023 is a reply to message #644919] Wed, 15 December 2010 04:20 Go to previous messageGo to next message
Eclipse UserFriend
I think it would be necessary to add the bundle identity (bundle symbolic name and version or possibly bundle id) to Logback's Mapped Diagnostic Context before it would be possible to refer to the bundle identity in an encoder pattern.

This could be done, but I'm not convinced that Virgo should incur that overhead on every logging call.

An alternative would be to build logic into the exception constructor to derive the bundle name and add it to the exception message. You could examine the stack and then use FrameworkUtil.getBundle(Class< ? >) to get the Bundle from the appropriate class in the stack.

Re: Logging the bundle name [message #652177 is a reply to message #645023] Wed, 02 February 2011 16:32 Go to previous messageGo to next message
Eclipse UserFriend
How about adding the bundle information to the MDC within the proxies generated for OSGi service calls?

i.e.

try {
  MDC.put("Bundle-SymbolicName", ...);
  MDC.put("Bundle-ID", ...);
  <service call here>
} finally {
  MDC.remove("Bundle-SymbolicName");
  MDC.remove("Bundle-ID");
}

Glyn - is this what you were thinking of when you said that it could be done but you were concerned about overhead?

Cheers,
Raman

[Updated on: Wed, 02 February 2011 16:32] by Moderator

Re: Logging the bundle name [message #652178 is a reply to message #652177] Wed, 02 February 2011 16:37 Go to previous messageGo to next message
Eclipse UserFriend
Not really: the overhead I had in mind was if Virgo was to add those items to a MDC for every logging call.

However, I think gathering the necessary information when the exception occurs is a better design. Would that work in your situation?
Re: Logging the bundle name [message #652183 is a reply to message #652178] Wed, 02 February 2011 17:11 Go to previous messageGo to next message
Eclipse UserFriend
It probably would but only for exceptions, and only those exceptions which I specifically instrumented. What would be better is a generic solution that would work for all logging messages.

What do you think about the approach I described? The only overhead would be the MDC put and release calls on each service call. Unfortunately, it won't cover every situation -- for example, code that runs outside the context of a service call, but it would help nonetheless.

Cheers,
Raman

[Updated on: Wed, 02 February 2011 17:29] by Moderator

Re: Logging the bundle name [message #652356 is a reply to message #652183] Thu, 03 February 2011 11:28 Go to previous messageGo to next message
Eclipse UserFriend
Hi Raman,

maybe using AspectJ would be a solution for your problem. You could write an aspect that is intercepting every log call or catching any exception. Then you could add the needed information and continue with the regular program.
Re: Logging the bundle name [message #652368 is a reply to message #652356] Thu, 03 February 2011 12:00 Go to previous messageGo to next message
Eclipse UserFriend
Hi Raman

Your approach seems reasonable.

I would personally choose AspectJ, like Frieder suggested, and use compile-time weaving for simplicity of interaction with OSGi.
Re: Logging the bundle name [message #652405 is a reply to message #652368] Thu, 03 February 2011 13:45 Go to previous messageGo to next message
Eclipse UserFriend
Using Aspects sounds like a reasonable interim approach.

I guess in the long run though this sort of thing will need to be part of the toolset. Not being able to determine out of the box which bundle logged a message is a big information deficit, and I'm surprised this isn't a common request.
Re: Logging the bundle name [message #652441 is a reply to message #652405] Thu, 03 February 2011 17:43 Go to previous messageGo to next message
Eclipse UserFriend
I think the usual approach is to observe the class name in a log entry and infer the bundle from it.
Re: Logging the bundle name [message #652450 is a reply to message #652441] Thu, 03 February 2011 18:55 Go to previous messageGo to next message
Eclipse UserFriend
Fair enough -- this situation has come up for me in cases where multiple service bundles access shared utility bundles, and the log statements in the shared utility bundles need to list the important contextual information, which is the service bundle.

But in that case, a baked in solution wouldn't know which bundle to log anyway, so we are back to the explicit aspect/MDC solution. Makes sense.

Thanks.
Re: Logging the bundle name [message #690272 is a reply to message #652450] Wed, 29 June 2011 05:55 Go to previous messageGo to next message
Eclipse UserFriend
FYI I got exactly what I wanted by using a scoped plan. Then Virgo sends all the output to an application-specific log.
Re: Logging the bundle name [message #690302 is a reply to message #690272] Wed, 29 June 2011 06:31 Go to previous message
Eclipse UserFriend
Not all situations can accommodate a scoped plan, but I'm glad it works for you.
Previous Topic:Virgo Kernel turns off MBeanServer creation
Next Topic:WebApplicationStartFailedException
Goto Forum:
  


Current Time: Wed Jul 02 00:06:08 EDT 2025

Powered by FUDForum. Page generated in 0.16464 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top