[
https://issues.apache.org/jira/browse/LOG4J2-730?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14087554#comment-14087554
]
Remko Popma commented on LOG4J2-730:
------------------------------------
Would it work if we changed the Log4jContextFactory constructor to the code
below?
Your custom factory could then call {{super(createMyCustomSelector());}} in its
constructor.
{code}
public Log4jContextFactory() {
this(createSelector());
}
public Log4jContextFactory(ContextSelector selector) {
this.selector = selector;
}
private static ContextSelector createSelector() {
final String sel =
PropertiesUtil.getProperties().getStringProperty(Constants.LOG4J_CONTEXT_SELECTOR);
if (sel != null) {
try {
return Loader.newCheckedInstanceOf(sel, ContextSelector.class);
} catch (final Exception ex) {
LOGGER.error("Unable to create context {}", sel, ex);
}
}
return new ClassLoaderContextSelector();
}
{code}
> Log4jContextFactory selector discovery logic is not extensible
> --------------------------------------------------------------
>
> Key: LOG4J2-730
> URL: https://issues.apache.org/jira/browse/LOG4J2-730
> Project: Log4j 2
> Issue Type: Improvement
> Components: Core
> Affects Versions: 2.0
> Reporter: Mariano Gonzalez
>
> I want to write my own LoggerContextFactory which forces my specific instance
> of ContextSelector and sets some system properties.
> I'd like to extend Log4jContextFactory class to just add this logic and reuse
> the rest of the code, however that doesn't seem possible since the selector
> attribute is private and the piece of code that fetches it is embedded in the
> constructor.
> I think it makes sense to have the selector as a private field, but if the
> code to fetch it could be a protected one so that it can be overridden, that
> would enable use cases like this.
> Thanks
--
This message was sent by Atlassian JIRA
(v6.2#6252)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]