| Logging the bundle name [message #644919] |
Tue, 14 December 2010 13:18  |
Raman Gupta Messages: 12 Registered: December 2010 |
Junior Member |
|
|
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 #652177 is a reply to message #645023] |
Wed, 02 February 2011 16:32   |
Raman Gupta Messages: 12 Registered: December 2010 |
Junior Member |
|
|
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] Report message to a moderator
|
|
|
|
| Re: Logging the bundle name [message #652183 is a reply to message #652178] |
Wed, 02 February 2011 17:11   |
Raman Gupta Messages: 12 Registered: December 2010 |
Junior Member |
|
|
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] Report message to a moderator
|
|
|
| Re: Logging the bundle name [message #652356 is a reply to message #652183] |
Thu, 03 February 2011 11:28   |
|
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.
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.01816 seconds