Apache logging services logo Apache log4j logo




In Log4j 2 a plugin is declared by adding a Plugin annotation to the class declaration. During initialization the Configuration will invoke the PluginManager to locate all the Log4j plugins that are located in the declared packages. As the configuration is processed the appropriate plugins will be automatically configured and initialized. Log4j 2 utilizes a few different categories of plugins which are described in the following sections.




Attribute Types

The parameter must resolve to a String, although it can be the String representation of a boolean. numeric value, or any other Object that can be created from a String value.








Plugin Preloading

Scanning for annotated classes dynamically takes a bit of time during application initialization. Log4j avoids this by scanning its classes during the build. In the Maven build, the PluginManager is invoked as shown below and then the resulting Map is stored in a file in the jar being constructed. Log4j will locate all the files created this way and and preload them, which shortens startup time considerably. Adding the following plugin definition to your project's pom.xml will cause the plugin manager to be called during the build. It will store the resulting file in the correct location under the directory specified in the first argument after scanning all the components located under the package specified in the second argument.


Using the Java annotation processor

Annotated classes marked with @Plugin or @PluginAliases are now automatically preloaded when you include the log4j-core artifact.