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

Rob Spoor commented on LOG4J2-3640:
-----------------------------------

I see your point. I tried with only the annotation processor added to the 
plugin, and that already made the project work. (The log4j3 test didn't have 
any adds, those were only present in the plugin, which was the only JPMS 
module). I could even remove the {{test.log4j.plugin}} package from the XML 
configurations.

While you say that you never recommended using class path scanning, it was 
still a possibility. Any plugin written without the annotation processor will 
not work in Log4j 3.x. Given that the documentation I found doesn't include any 
mentions about the annotation processor, that may be quite a few plugins.

Documentation, from searching on "log4j custom appender":
* https://logging.apache.org/log4j/2.x/manual/extending.html (yes, Log4j itself 
only mentions the annotations themselves for most extensions)
* https://www.baeldung.com/log4j2-custom-appender
* https://kkjavatutorials.com/how-to-create-a-custom-appender-in-log4j2/
* https://relentlesscoding.com/posts/how-to-write-a-custom-appender-in-log4j2/

> @Plugin not compatible between 2.x and 3.x
> ------------------------------------------
>
>                 Key: LOG4J2-3640
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-3640
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Plugins
>    Affects Versions: 3.0.0
>            Reporter: Rob Spoor
>            Priority: Major
>
> I had an issue with resolving Log4j2 2.19.0 as a module. While I resolved the 
> issue by adding an explicit {{--add-opens}} clause, I still found something 
> that appears to be an issue.
> According to [this 
> comment|https://stackoverflow.com/questions/74592131/maven-log4j-class-not-found#comment131670094_74592131]
>  from [~rgoers], {quote}Plugins should NOT need to be recompiled
> {quote}
> Because of an earlier comment on my question I had tried to use version 
> 3.0.0-SNAPSHOT. That produced some compiler errors. While some were easy 
> enough to solve to be compatible with versions 2.19.0 and 3.0.0-SNAPSHOT, the 
> moved {{@Plugin}} annotation meant I couldn't compile my project for both 
> versions 2.19.0 and 3.0.0-SNAPSHOT. That made me believe that plugins written 
> for 2.19.0 are *not* compatible with 3.0.0.
> I have created a little POC: [https://github.com/robtimus/log4j-compat-test]. 
> This consists of 3 Maven modules:
>  * A module with only a simple plugin
>  * A module to test this plugin in Log4j2 2.19.0
>  * A module to test this plugin in Log4j2 3.0.0-SNAPSHOT
> The entire project can be tested using {{mvn test}}. Right now this fails 
> because, as expected, the moving of the {{@Plugin}} annotation caused the 
> plugin to *not* be resolved.
> I've also included a "legacy" plugin class in the 3.0.0-SNAPSHOT test module 
> that shows that the deprecated annotations 
> {{org.apache.logging.log4j.core.config.plugins.PluginAttribute}} and 
> {{org.apache.logging.log4j.core.config.plugins.PluginFactory}} still work; 
> it's the (forced) replacement of 
> {{org.apache.logging.log4j.core.config.plugins.Plugin}} with both 
> {{org.apache.logging.log4j.plugins.Plugin}} and 
> {{org.apache.logging.log4j.plugins.Configurable}} that causes the plugin 
> written for version 2.19.0 to not work.
> ----
> I think that the following should be done, to prevent forcing people rewrite 
> all of their existing plugins:
>  * Re-adding the {{org.apache.logging.log4j.core.config.plugins.Plugin}} 
> annotation, but make it deprecated.
>  * The plugin registration code should treat this plugin as a combination of 
> {{org.apache.logging.log4j.plugins.Plugin}} and 
> {{{}org.apache.logging.log4j.plugins.Configurable{}}}. There may be another 
> one, for the {{category}} attribute of the old annotation, but I couldn't 
> find out which one yet.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to