[
https://issues.apache.org/jira/browse/LOG4J2-589?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14146441#comment-14146441
]
Remko Popma commented on LOG4J2-589:
------------------------------------
I see some code in AbstractConfiguration that looks like it intends to load
custom Levels from the configuration. However, it is not clear to me how this
is supposed to work. If I create a plugin with {{category="Level"}} its factory
method is never invoked...
Am I doing something wrong, or is the code in AbstractConfiguration used for
something else? (Or is it broken?)
{code}
//AbstractConfiguration
public void start() {
LOGGER.debug("Starting configuration {}", this);
this.setStarting();
pluginManager.collectPlugins(pluginPackages);
final PluginManager levelPlugins = new PluginManager(Level.CATEGORY); //
<--- this constant has value "Level"
levelPlugins.collectPlugins(pluginPackages);
final Map<String, PluginType<?>> plugins = levelPlugins.getPlugins();
if (plugins != null) {
for (final PluginType<?> type : plugins.values()) {
try {
// Cause the class to be initialized if it isn't already.
Loader.initializeClass(type.getPluginClass().getName(),
type.getPluginClass().getClassLoader());
} catch (final Exception e) {
LOGGER.error("Unable to initialize {} due to {}",
type.getPluginClass().getName(), e.getClass()
.getSimpleName(), e);
}
}
}
{code}
A simple custom Level plugin:
{code}
// TBD: if category="Level", the factory method is never invoked... Why?
@Plugin(name = "CustomLevel", category = "Core") // if category="Core" it works
public final class CustomLevelPlugin {
private CustomLevelPlugin() {
}
@PluginFactory
public static Level createLevel(
@PluginAttribute("name") final String levelName,
@PluginAttribute("intLevel") final int intLevel) {
Level result = Level.forName(levelName, intLevel);
return result;
}
}
{code}
> Allow the use of custom levels in configuration
> -----------------------------------------------
>
> Key: LOG4J2-589
> URL: https://issues.apache.org/jira/browse/LOG4J2-589
> Project: Log4j 2
> Issue Type: Improvement
> Components: Configurators
> Affects Versions: 2.0-rc1
> Reporter: James Hutton
> Labels: configuration, custom, level
> Fix For: 2.2
>
>
> Previous title: Use forName instead of getLevel and valueOf for configuration
> Without this one cannot use custom log levels in configuration without
> forking a large amount of code. Either the forName method needs to be
> removed and custom log levels should be explicitly forbidden, or support
> should be consistent.
> Classes that would need to be modified:
> BaseConfiguration, NullConfiguration, and DefaultConfiguration.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]