[
https://issues.apache.org/jira/browse/FELIX-6274?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17112486#comment-17112486
]
Tom Watson commented on FELIX-6274:
-----------------------------------
I put this comment in the PR, but reflecting it here for wider discussion:
For your scenario is R6 or R7 log specification being used? or maybe both at
the same time?
My opinion is if SCR itself is wired to the R7 log package then it must always
use the new Logger interface to log all messages. If SCR is logging messages
related to a specific component then SCR must call the
LoggerFactory.getLogger(Bundle bundle, String name, Class loggerType) method
passing the bundle declaring the component to obtain the Logger. This is
described at
https://docs.osgi.org/specification/osgi.cmpn/7.0.0/service.component.html#d0e41804
In that case I believe SCR must use its own BundleContext to get the
LoggerFactory service NOT the context of the extendee bundle. I think it would
be unfortunate to resort to reflection to call the Logger because SCR is very
noisy with its debug logging. That is optimized out by the log service
implementation if debug is not enabled with LoggerAdmin, but now we may put a
reflective call before that optimization can be used.
Unfortunately Felix SCR also tries to support the R6 LogService (perhaps we
should rip that out?). For R6 LogService SCR must use the BundleContext of the
extendee. The R6 Declarative Service spec states:
> When SCR must log an error message to the Log Service, it must use a Log
> Service obtained using the component's Bundle Context so that the resulting
> Log Entry is associated with the component's bundle.
So in that case I see the need to fall back to reflection.
But first I think we should decide if we want to support R6 LogService at all
in SCR. My vote is to rip that out and only support R7 which allows us to only
use the context of SCR itself to obtain the LoggerFactory therefore avoiding
any possible cast exceptions.
> Potential Class Space problems with multiple Log Service APIs
> -------------------------------------------------------------
>
> Key: FELIX-6274
> URL: https://issues.apache.org/jira/browse/FELIX-6274
> Project: Felix
> Issue Type: Bug
> Components: Declarative Services (SCR)
> Affects Versions: scr-2.1.20
> Reporter: Timothy James Ward
> Priority: Major
> Fix For: scr-2.1.22
>
>
> The Declarative Services specification requires SCR to inject Logger
> implementations into a DS component (if requested). In order to find a
> suitable Log Service SCR uses its *own* BundleContext, not the context of the
> bundle being extended. This means that if the bundle being extended has a
> different view of the Log Service API then the injection will fail with a
> ClassCastException.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)