You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Matt Sicker (Jira)" <ji...@apache.org> on 2019/10/06 18:15:00 UTC

[jira] [Commented] (LOG4J2-2700) Add support for injecting plugin configuration via builder methods

    [ https://issues.apache.org/jira/browse/LOG4J2-2700?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16945420#comment-16945420 ] 

Matt Sicker commented on LOG4J2-2700:
-------------------------------------

Ooh, nice issue id. I'll ask here before submitting another issue: would it make sense to also allow for constructor-based injection? This could simplify some plugins that only take a couple parameters. This could also be combined with builders to allow for a programmatic way to enforce required arguments versus optional arguments by including the required ones in the builder constructor (or in the static method for creating the builder) and leaving the optional arguments to be fields or methods of the builder class. This pattern statically enforces values to some extent (though it doesn't prevent the calling code from just using null or similar values).

> Add support for injecting plugin configuration via builder methods
> ------------------------------------------------------------------
>
>                 Key: LOG4J2-2700
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-2700
>             Project: Log4j 2
>          Issue Type: Improvement
>          Components: Plugins
>            Reporter: Matt Sicker
>            Assignee: Matt Sicker
>            Priority: Major
>             Fix For: 3.0.0
>
>
> Prior to this feature, a plugin builder class could only have configuration values injected via fields. While all Log4j plugin builder classes typically include corresponding setFoo or withFoo methods to set values to all those fields, these methods were not used by the plugin system.
> This feature is to expand the support of using @PluginAttribute, @PluginElement, @PluginValue, @PluginNode, @PluginConfiguration, @PluginAliases, and any validation annotations on single-argument methods in a builder class. The default name extracted for these methods should be the "foo" from setFoo or withFoo if named that way, or it should use the name of the method parameter otherwise.
> As with parameters injected via a static factory method, these values should be validated by checking their types as well as validation constraints before being bound. Default values can be specified the same way as well. This allows for each setter or wither method to perform any addition programmatic validation if necessary, and it reduces coupling of implementation details to the public API of a plugin.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)