blob: 08f40d84d8812703d4f9abed2bfa731008c63a65 [file] [log] [blame]
<!DOCTYPE html>
<!--
| Generated by Apache Maven Doxia Site Renderer 1.11.1 from target/generated-sources/site/xdoc/manual/plugins.xml at 2024-03-06
| Rendered using Apache Maven Fluido Skin 1.11.2
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="generator" content="Apache Maven Doxia Site Renderer 1.11.1" />
<meta name="author" content="Ralph Goers" />
<meta name="author" content="Matt Sicker" />
<title>Log4j &#x2013; Log4j 2 Plugins</title>
<link rel="stylesheet" href="../css/apache-maven-fluido-1.11.2.min.css" />
<link rel="stylesheet" href="../css/site.css" />
<link rel="stylesheet" href="../css/print.css" media="print" />
<script src="../js/apache-maven-fluido-1.11.2.min.js"></script>
</head>
<body class="topBarDisabled">
<div class="container-fluid">
<header>
<div id="banner">
<div class="pull-left"><a href="../../.." id="bannerLeft"><img src="../images/ls-logo.jpg" alt="" style="" /></a></div>
<div class="pull-right"><a href=".././" id="bannerRight"><img src="../images/logo.png" alt="" style="" /></a></div>
<div class="clear"><hr/></div>
</div>
<div id="breadcrumbs">
<ul class="breadcrumb">
<li id="publishDate">Last Published: 2024-03-06<span class="divider">|</span>
</li>
<li id="projectVersion">Version: 2.23.1</li>
<li class="pull-right"><span class="divider">|</span>
<a href="https://github.com/apache/logging-log4j2" class="externalLink" title="GitHub">GitHub</a></li>
<li class="pull-right"><span class="divider">|</span>
<a href="../../../" title="Logging Services">Logging Services</a></li>
<li class="pull-right"><span class="divider">|</span>
<a href="https://www.apache.org/" class="externalLink" title="Apache">Apache</a></li>
<li class="pull-right"><a href="https://cwiki.apache.org/confluence/display/LOGGING/Log4j" class="externalLink" title="Logging Wiki">Logging Wiki</a></li>
</ul>
</div>
</header>
<div class="row-fluid">
<header id="leftColumn" class="span2">
<nav class="well sidebar-nav">
<ul class="nav nav-list">
<li class="nav-header"><img class="imageLink" src="../img/glyphicons/home.png" alt="Apache Log4j™ 2" style="border: 0;" /> Apache Log4j™ 2</li>
<li><a href="../index.html" title="About"><span class="none"></span>About</a></li>
<li><a href="../download.html" title="Download"><span class="none"></span>Download</a></li>
<li><a href="../support.html" title="Support"><span class="none"></span>Support</a></li>
<li><a href="../maven-artifacts.html" title="Maven, Ivy, Gradle Artifacts"><span class="icon-chevron-right"></span>Maven, Ivy, Gradle Artifacts</a></li>
<li><a href="../release-notes.html" title="Release Notes"><span class="none"></span>Release Notes</a></li>
<li><a href="../faq.html" title="FAQ"><span class="none"></span>FAQ</a></li>
<li><a href="../performance.html" title="Performance"><span class="icon-chevron-right"></span>Performance</a></li>
<li><a href="../articles.html" title="Articles and Tutorials"><span class="none"></span>Articles and Tutorials</a></li>
<li><a href="../security.html" title="Security"><span class="icon-chevron-right"></span>Security</a></li>
<li class="nav-header"><img class="imageLink" src="../img/glyphicons/book.png" alt="Manual" style="border: 0;" /> Manual</li>
<li><a href="../manual/index.html" title="Introduction"><span class="none"></span>Introduction</a></li>
<li><a href="../manual/architecture.html" title="Architecture"><span class="none"></span>Architecture</a></li>
<li><a href="../manual/api-separation.html" title="API Separation"><span class="none"></span>API Separation</a></li>
<li><a href="../manual/migration.html" title="Log4j 1.x Migration"><span class="icon-chevron-right"></span>Log4j 1.x Migration</a></li>
<li><a href="../manual/api.html" title="Java API"><span class="icon-chevron-right"></span>Java API</a></li>
<li><a href="../../kotlin" title="Kotlin API"><span class="none"></span>Kotlin API</a></li>
<li><a href="../../scala" title="Scala API"><span class="none"></span>Scala API</a></li>
<li><a href="../manual/configuration.html" title="Configuration"><span class="icon-chevron-right"></span>Configuration</a></li>
<li><a href="../manual/usage.html" title="Usage"><span class="icon-chevron-right"></span>Usage</a></li>
<li><a href="../manual/webapp.html" title="Web Applications and JSPs"><span class="icon-chevron-right"></span>Web Applications and JSPs</a></li>
<li><a href="../manual/lookups.html" title="Lookups"><span class="icon-chevron-right"></span>Lookups</a></li>
<li><a href="../manual/appenders.html" title="Appenders"><span class="icon-chevron-right"></span>Appenders</a></li>
<li><a href="../manual/layouts.html" title="Layouts"><span class="icon-chevron-right"></span>Layouts</a></li>
<li><a href="../manual/filters.html" title="Filters"><span class="icon-chevron-right"></span>Filters</a></li>
<li><a href="../manual/async.html" title="Async Loggers"><span class="icon-chevron-right"></span>Async Loggers</a></li>
<li><a href="../manual/garbagefree.html" title="Garbage-free Logging"><span class="icon-chevron-right"></span>Garbage-free Logging</a></li>
<li><a href="../manual/jmx.html" title="JMX"><span class="none"></span>JMX</a></li>
<li><a href="../manual/logsep.html" title="Logging Separation"><span class="none"></span>Logging Separation</a></li>
<li><a href="../manual/extending.html" title="Extending Log4j"><span class="icon-chevron-right"></span>Extending Log4j</a></li>
<li class="active"><a><span class="icon-chevron-down"></span>Plugins</a>
<ul class="nav nav-list">
<li><a href="../manual/plugins.html#Core" title="Core"><span class="none"></span>Core</a></li>
<li><a href="../manual/plugins.html#Converters" title="Converters"><span class="none"></span>Converters</a></li>
<li><a href="../manual/plugins.html#KeyProviders" title="Key Providers"><span class="none"></span>Key Providers</a></li>
<li><a href="../manual/plugins.html#Lookups" title="Lookups"><span class="none"></span>Lookups</a></li>
<li><a href="../manual/plugins.html#TypeConverters" title="Type Converters"><span class="none"></span>Type Converters</a></li>
<li><a href="../manual/plugins.html#DeveloperNotes" title="Developer Notes"><span class="none"></span>Developer Notes</a></li>
</ul></li>
<li><a href="../manual/customconfig.html" title="Programmatic Log4j Configuration"><span class="icon-chevron-right"></span>Programmatic Log4j Configuration</a></li>
<li><a href="../manual/customloglevels.html" title="Custom Log Levels"><span class="icon-chevron-right"></span>Custom Log Levels</a></li>
<li class="nav-header"><img class="imageLink" src="../img/glyphicons/pencil.png" alt="For Contributors" style="border: 0;" /> For Contributors</li>
<li><a href="../guidelines.html" title="Guidelines"><span class="none"></span>Guidelines</a></li>
<li><a href="../javastyle.html" title="Style Guide"><span class="none"></span>Style Guide</a></li>
<li class="nav-header"><img class="imageLink" src="../img/glyphicons/cog.png" alt="Components" style="border: 0;" /> Components</li>
<li><a href="../log4j-api.html" title="API"><span class="none"></span>API</a></li>
<li><a href="../log4j-jcl.html" title="Commons Logging Bridge"><span class="none"></span>Commons Logging Bridge</a></li>
<li><a href="../log4j-1.2-api.html" title="Log4j 1.2 API"><span class="none"></span>Log4j 1.2 API</a></li>
<li><a href="../log4j-slf4j-impl.html" title="SLF4J Binding"><span class="none"></span>SLF4J Binding</a></li>
<li><a href="../log4j-jul.html" title="JUL Adapter"><span class="none"></span>JUL Adapter</a></li>
<li><a href="../log4j-jpl.html" title="JDK Platform Logger"><span class="none"></span>JDK Platform Logger</a></li>
<li><a href="../log4j-to-slf4j.html" title="Log4j 2 to SLF4J Adapter"><span class="none"></span>Log4j 2 to SLF4J Adapter</a></li>
<li><a href="../log4j-flume-ng.html" title="Apache Flume Appender"><span class="none"></span>Apache Flume Appender</a></li>
<li><a href="../log4j-taglib.html" title="Log4j Tag Library"><span class="none"></span>Log4j Tag Library</a></li>
<li><a href="../log4j-jmx-gui.html" title="Log4j JMX GUI"><span class="none"></span>Log4j JMX GUI</a></li>
<li><a href="../log4j-web.html" title="Log4j Web Application Support"><span class="none"></span>Log4j Web Application Support</a></li>
<li><a href="../log4j-jakarta-web.html" title="Log4j Jakarta Web Application Support"><span class="none"></span>Log4j Jakarta Web Application Support</a></li>
<li><a href="../log4j-appserver.html" title="Log4j Application Server Integration"><span class="none"></span>Log4j Application Server Integration</a></li>
<li><a href="../log4j-couchdb.html" title="Log4j CouchDB appender"><span class="none"></span>Log4j CouchDB appender</a></li>
<li><a href="../log4j-mongodb3.html" title="Log4j MongoDB3 appender"><span class="none"></span>Log4j MongoDB3 appender</a></li>
<li><a href="../log4j-mongodb4.html" title="Log4j MongoDB4 appender"><span class="none"></span>Log4j MongoDB4 appender</a></li>
<li><a href="../log4j-cassandra.html" title="Log4j Cassandra appender"><span class="none"></span>Log4j Cassandra appender</a></li>
<li><a href="../log4j-iostreams.html" title="Log4j IO Streams"><span class="none"></span>Log4j IO Streams</a></li>
<li><a href="../log4j-docker.html" title="Log4j Docker Support"><span class="none"></span>Log4j Docker Support</a></li>
<li><a href="../log4j-kubernetes.html" title="Log4j Kubernetes Support"><span class="none"></span>Log4j Kubernetes Support</a></li>
<li><a href="../log4j-spring-boot.html" title="Log4j Spring Boot"><span class="none"></span>Log4j Spring Boot</a></li>
<li><a href="../log4j-spring-cloud-config-client.html" title="Log4j Spring Cloud Config Client"><span class="none"></span>Log4j Spring Cloud Config Client</a></li>
<li class="nav-header"><img class="imageLink" src="../img/glyphicons/tag.png" alt="Related Projects" style="border: 0;" /> Related Projects</li>
<li><a href="../../../chainsaw/2.x/index.html" title="Chainsaw"><span class="none"></span>Chainsaw</a></li>
<li><a href="../../../log4cxx/latest_stable/index.html" title="Log4Cxx"><span class="none"></span>Log4Cxx</a></li>
<li><a href="../../../log4j-audit/latest/index.html" title="Log4j Audit"><span class="none"></span>Log4j Audit</a></li>
<li><a href="../../kotlin" title="Log4j Kotlin"><span class="none"></span>Log4j Kotlin</a></li>
<li><a href="../../scala" title="Log4j Scala"><span class="none"></span>Log4j Scala</a></li>
<li><a href="../../transform" title="Log4j Transform"><span class="none"></span>Log4j Transform</a></li>
<li><a href="../../../log4net/index.html" title="Log4Net"><span class="none"></span>Log4Net</a></li>
<li class="nav-header"><img class="imageLink" src="../img/glyphicons/link.png" alt="Legacy Sites" style="border: 0;" /> Legacy Sites</li>
<li><a href="../../log4j-2.12.4/" title="Log4j 2.12.4 - Java 7"><span class="none"></span>Log4j 2.12.4 - Java 7</a></li>
<li><a href="../../log4j-2.3.2/" title="Log4j 2.3.2 - Java 6"><span class="none"></span>Log4j 2.3.2 - Java 6</a></li>
<li><a href="../../1.2/" title="Log4j 1.2 - End of Life"><span class="none"></span>Log4j 1.2 - End of Life</a></li>
<li class="nav-header"><img class="imageLink" src="../img/glyphicons/info.png" alt="Project Information" style="border: 0;" /> Project Information</li>
<li><a href="../team.html" title="Project Team"><span class="none"></span>Project Team</a></li>
<li><a href="https://www.apache.org/licenses/LICENSE-2.0" class="externalLink" title="Project License"><span class="none"></span>Project License</a></li>
<li><a href="https://github.com/apache/logging-log4j2" class="externalLink" title="Source Repository"><span class="none"></span>Source Repository</a></li>
<li><a href="../runtime-dependencies.html" title="Runtime Dependencies"><span class="none"></span>Runtime Dependencies</a></li>
<li><a href="../javadoc.html" title="Javadoc"><span class="none"></span>Javadoc</a></li>
<li><a href="../thanks.html" title="Thanks"><span class="none"></span>Thanks</a></li>
</ul>
</nav>
<div class="well sidebar-nav">
<div id="poweredBy">
<div class="clear"></div>
<div class="clear"></div>
<div class="clear"></div>
<a href="http://maven.apache.org/" title="Built by Maven" class="poweredBy"><img class="builtBy" alt="Built by Maven" src="../images/logos/maven-feather.png" /></a>
</div>
</div>
</header>
<main id="bodyColumn" class="span10" >
<section>
<h2><a name="Plugins"></a>Plugins</h2>
<section>
<h3><a name="Introduction"></a>Introduction</h3>
<a name="Introduction"></a>
<p>
Log4j 1.x allowed for extension by requiring class attributes on most of the configuration
declarations. In the case of some elements, notably the PatternLayout, the only way to add
new pattern converters was to extend the PatternLayout class and add them via code. One
goal of Log4j 2 is to make extending it extremely easy through the use of plugins.
</p>
<p>
In Log4j 2 a plugin is declared by adding a
<a href="../log4j-core/apidocs/org/apache/logging/log4j/core/config/plugins/Plugin.html" class="javadoc">@Plugin</a>
annotation to the class declaration. During initialization the
<a href="../log4j-core/apidocs/org/apache/logging/log4j/core/config/Configuration.html" class="javadoc">Configuration</a>
will invoke the
<a href="../log4j-core/apidocs/org/apache/logging/log4j/core/config/plugins/util/PluginManager.html" class="javadoc">PluginManager</a>
to load the built-in Log4j plugins as well as any custom plugins. The <code>PluginManager</code> locates
plugins by looking in five places:
</p>
<ol style="list-style-type: decimal">
<li>Serialized plugin listing files on the classpath. These files are generated automatically during
the build (more details below).</li>
<li>(OSGi only) Serialized plugin listing files in each active OSGi bundle. A <code>BundleListener</code>
is added on activation to continue checking new bundles after <code>log4j-core</code> has started.</li>
<li><b>(Deprecated)</b> A comma-separated list of packages specified by the <code>log4j.plugin.packages</code>
system property.</li>
<li><b>(Deprecated)</b> Packages passed to the static <code>PluginManager.addPackages</code> method (before Log4j configuration
occurs).</li>
<li><b>(Deprecated)</b> The <a href="./configuration.html#ConfigurationSyntax">packages</a> declared in your log4j2
configuration file.</li>
</ol>
<p>
If multiple Plugins specify the same (case-insensitive) <code>name</code>, then the load order above
determines which one will be used. For example, to override the <code>File</code> plugin which is provided
by the built-in <code>FileAppender</code> class, you would need to place your plugin in a JAR file in the
CLASSPATH ahead of<code>log4j-core.jar</code>. This is not recommended; plugin name collisions will cause a
warning to be emitted. Note that in an OSGi environment, the order that bundles are scanned for plugins
generally follows the same order that bundles were installed into the framework. See
<a class="javadoc" href="https://www.osgi.org/javadoc/r5/core/org/osgi/framework/BundleContext.html#getBundles()">getBundles()</a>
and
<a class="javadoc" href="https://www.osgi.org/javadoc/r5/core/org/osgi/framework/SynchronousBundleListener.html">SynchronousBundleListener</a>.
In short, name collisions are even more unpredictable in an OSGi environment.
</p>
<p>
Serialized plugin listing files are generated by an annotation processor contained in the
log4j-core artifact which will automatically scan your code for Log4j 2 plugins and output a metadata
file in your processed classes. There is nothing extra that needs to be done to enable this; the Java
compiler will automatically pick up the annotation processor on the class path unless you explicitly
disable it. In that case, it would be important to add another compiler pass to your build process that
only handles annotation processing using the Log4j 2 annotation processor class,
<code>org.apache.logging.log4j.core.config.plugins.processor.PluginProcessor</code>. To do this using
Apache Maven, add the following execution to your <i>maven-compiler-plugin</i> (version 2.2 or higher)
build plugin:
</p>
<div>
<pre class="prettyprint linenums">
&lt;plugin&gt;
&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
&lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
&lt;version&gt;3.1&lt;/version&gt;
&lt;executions&gt;
&lt;execution&gt;
&lt;id&gt;log4j-plugin-processor&lt;/id&gt;
&lt;goals&gt;
&lt;goal&gt;compile&lt;/goal&gt;
&lt;/goals&gt;
&lt;phase&gt;process-classes&lt;/phase&gt;
&lt;configuration&gt;
&lt;proc&gt;only&lt;/proc&gt;
&lt;annotationProcessors&gt;
&lt;annotationProcessor&gt;org.apache.logging.log4j.core.config.plugins.processor.PluginProcessor&lt;/annotationProcessor&gt;
&lt;/annotationProcessors&gt;
&lt;/configuration&gt;
&lt;/execution&gt;
&lt;/executions&gt;
&lt;/plugin&gt;
</pre></div>
<p>
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.
</p>
</section>
<section>
<h3><a name="Core"></a>Core</h3>
<a name="Core"></a>
<p>
Core plugins are those that are directly represented by an element in a configuration file, such as an
Appender, Layout, Logger or Filter. Custom plugins that conform to the rules laid out in the next paragraph
may simply be referenced in the configuration, provided they are appropriate configured to be
loaded by the PluginManager.
</p>
<p>
Every Core plugin must declare a static method annotated with <code>@PluginFactory</code> or
<code>@PluginBuilderFactory</code>. The former is used for static factory methods that provide all options
as method parameters, and the latter is used to construct a new <code>Builder&lt;T&gt;</code> class whose
fields are used for injecting attributes and child nodes. To allow the <code>Configuration</code> to pass
the correct parameters to the method, every parameter to the method must be annotated as one of the following
attribute types. Each attribute or element annotation must include the name that must be present in the
configuration in order to match the configuration item to its respective parameter. For plugin builders,
the names of the fields will be used by default if no name is specified in the annotation. There are dozens
of plugins in Log4j Core that can be used as examples for more complex scenarios including hierarchical
builder classes (e.g., see <code>FileAppender</code>). See <a href="extending.html#Plugin_Builders">Extending
Log4j with Plugin Builders</a> for more details.
</p>
<section>
<h4><a name="Attribute_Types"></a>Attribute Types</h4>
<dl>
<dt><a href="../log4j-core/apidocs/org/apache/logging/log4j/core/config/plugins/PluginAttribute.html" class="javadoc">PluginAttribute</a></dt>
<dd>The parameter must be convertible from a String using a <a href="#TypeConverters">TypeConverter</a>.
Most built-in types are already supported, but custom <code>TypeConverter</code> plugins may also be
provided for more type support. Note that <code>PluginBuilderAttribute</code> can be used in builder class
fields as an easier way to provide default values.</dd>
<dt><a href="../log4j-core/apidocs/org/apache/logging/log4j/core/config/plugins/PluginElement.html" class="javadoc">PluginElement</a></dt>
<dd>The parameter may represent a complex object that itself has parameters that can be configured.
This also supports injecting an array of elements.</dd>
<dt><a href="../log4j-core/apidocs/org/apache/logging/log4j/core/config/plugins/PluginConfiguration.html" class="javadoc">PluginConfiguration</a></dt>
<dd>The current <code>Configuration</code> object will be passed to the plugin as a parameter.</dd>
<dt><a href="../log4j-core/apidocs/org/apache/logging/log4j/core/config/plugins/PluginNode.html" class="javadoc">PluginNode</a></dt>
<dd>The current <code>Node</code> being parsed will be passed to the plugin as a parameter.</dd>
<dt><a href="../log4j-core/apidocs/org/apache/logging/log4j/core/config/plugins/PluginValue.html" class="javadoc">PluginValue</a></dt>
<dd>The value of the current <code>Node</code> or its attribute named <code>value</code>.</dd>
</dl>
</section><section>
<h4><a name="Constraint_Validators"></a>Constraint Validators</h4>
<p>
Plugin factory fields and parameters can be automatically validated at runtime using constraint validators
inspired by the <a class="externalLink" href="https://beanvalidation.org/">Bean Validation spec</a>. The following annotations
are bundled in Log4j, but custom
<a href="../log4j-core/apidocs/org/apache/logging/log4j/core/config/plugins/validation/ConstraintValidator.html" class="javadoc">ConstraintValidators</a>
can be created as well.
</p>
<dl>
<dt><a href="../log4j-core/apidocs/org/apache/logging/log4j/core/config/plugins/validation/constraints/Required.html" class="javadoc">Required</a></dt>
<dd>This annotation validates that a value is non-empty. This covers a check for <code>null</code> as well
as several other scenarios: empty <code>CharSequence</code> objects, empty arrays, empty <code>Collection</code>
instances, and empty <code>Map</code> instances.</dd>
<dt><a href="../log4j-core/apidocs/org/apache/logging/log4j/core/config/plugins/validation/constraints/ValidHost.html" class="javadoc">ValidHost</a></dt>
<dd>This annotation validates that a value corresponds to a valid hostname. This uses the same validation as
<a class="javadoc" href="https://docs.oracle.com/javase/8/docs/api/java/net/InetAddress.html#getByName-java.lang.String-">InetAddress::getByName</a>.</dd>
<dt><a href="../log4j-core/apidocs/org/apache/logging/log4j/core/config/plugins/validation/constraints/ValidPort.html" class="javadoc">ValidPort</a></dt>
<dd>This annotation validates that a value corresponds to a valid port number between 0 and 65535.</dd>
</dl>
</section></section>
<section>
<h3><a name="Converters"></a>Converters</h3>
<a name="Converters"></a>
<p>
Converters are used by
<a href="../log4j-core/apidocs/org/apache/logging/log4j/core/layout/PatternLayout.html" class="javadoc">PatternLayout</a>
to render the elements identified by the conversion pattern. Every converter must specify its category as
&quot;Converter&quot; on the <code>@Plugin</code> annotation, have a static <code>newInstance</code> method that
accepts an array of <code>String</code>s as its only parameter and returns an instance of the Converter, and
must have a <code>@ConverterKeys</code> annotation present that contains the array of converter patterns
that will cause the Converter to be selected. Converters that are meant to handle <code>LogEvent</code>s
must extend the
<a href="../log4j-core/apidocs/org/apache/logging/log4j/core/layout/LogEventPatternConverter.html" class="javadoc">LogEventPatternConverter</a>
class and must implement a format method that accepts a <code>LogEvent</code> and a <code>StringBuilder</code>
as arguments. The Converter should append the result of its operation to the <code>StringBuilder</code>.
</p>
<p>
A second type of Converter is the FileConverter - which must have &quot;FileConverter&quot; specified in the
category attribute of the <code>@Plugin</code> annotation. While similar to a <code>LogEventPatternConverter</code>,
instead of a single format method these Converters will have two variations; one that takes an
<code>Object</code> and one that takes an array of <code>Object</code>s instead of the <code>LogEvent</code>.
Both append to the provided <code>StringBuilder</code> in the same fashion as a <code>LogEventPatternConverter</code>.
These Converters are typically used by the <code>RollingFileAppender</code> to construct the name of the
file to log to.
</p>
<p>
If multiple Converters specify the same <code>ConverterKeys</code>, then the load order above determines
which one will be used. For example, to override the <code>%date</code> converter which is provided by the
built-in <code>DatePatternConverter</code> class, you would need to place your plugin in a JAR file in the
CLASSPATH ahead of<code>log4j-core.jar</code>. This is not recommended; pattern ConverterKeys collisions
will cause a warning to be emitted. Try to use unique ConverterKeys for your custom pattern converters.
</p>
</section>
<section>
<h3><a name="KeyProviders"></a>KeyProviders</h3>
<a name="KeyProviders"></a>
<p>
Some components within Log4j may provide the ability to perform data encryption. These components require
a secret key to perform the encryption. Applications may provide the key by creating a class that
implements the
<a href="../log4j-core/apidocs/org/apache/logging/log4j/core/util/SecretKeyProvider.html" class="javadoc">SecretKeyProvider</a>
interface.
</p>
</section>
<section>
<h3><a name="Lookups"></a>Lookups</h3>
<a name="Lookups"></a>
<p>
Lookups are perhaps the simplest plugins of all. They must declare their type as &quot;Lookup&quot; on the
plugin annotation and must implement the
<a href="../log4j-core/apidocs/org/apache/logging/log4j/core/lookup/StrLookup.html" class="javadoc">StrLookup</a>
interface. They will have two methods; a
lookup method that accepts a String key and returns a String value and a second lookup method that
accepts both a LogEvent and a String key and returns a String. Lookups may be referenced by
specifying ${<var>name</var>:key} where <var>name</var> is the name specified in the Plugin annotation and
key is the name of the item to locate.
</p>
</section>
<section>
<h3><a name="TypeConverters"></a>TypeConverters</h3>
<a name="TypeConverters"></a>
<p>
<a href="../log4j-core/apidocs/org/apache/logging/log4j/core/config/plugins/convert/TypeConverter.html" class="javadoc">TypeConverter</a>s
are a sort of meta-plugin used for converting strings into other types in a plugin factory method
parameter. Other plugins can already be injected via the <code>@PluginElement</code> annotation; now, any
type supported by the type conversion system can be used in a <code>@PluginAttribute</code> parameter.
Conversion of enum types are supported on demand and do not require custom <code>TypeConverter</code>
classes. A large number of built-in Java classes are already supported; see
<a href="../log4j-core/apidocs/org/apache/logging/log4j/core/config/plugins/convert/TypeConverters.html" class="javadoc">TypeConverters</a>
for a more exhaustive listing.
</p>
<p>
Unlike other plugins, the plugin name of a <code>TypeConverter</code> is purely cosmetic. Appropriate
type converters are looked up via the <code>Type</code> interface rather than via <code>Class&lt;?&gt;</code>
objects only. Do note that <code>TypeConverter</code> plugins must have a default constructor.
When multiple converters match for a type, the first will be returned.
If any extends from <code>Comparable&lt;TypeConverter&lt;?&gt;&gt;</code>,
it will be used for determining the order.
</p>
</section>
</section>
<section>
<h2><a name="Developer_Notes"></a>Developer Notes</h2>
<a name="DeveloperNotes"></a>
<p>
If a plugin class implements
<a class="javadoc" href="https://docs.oracle.com/javase/6/docs/api/java/util/Collection.html">Collection</a> or
<a class="javadoc" href="https://docs.oracle.com/javase/6/docs/api/java/util/Map.html">Map</a>, then no
factory method is used. Instead, the class is instantiated using the default constructor, and all child
configuration nodes are added to the <code>Collection</code> or <code>Map</code>.
</p>
</section>
</main>
</div>
</div>
<hr/>
<footer>
<div class="container-fluid">
<div class="row-fluid">
<p align="center">Copyright &copy; 1999-2024 <a class="external" href="https://www.apache.org">The Apache Software Foundation</a>. All Rights Reserved.<br>
Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, and the Apache Logging project logo are trademarks of The Apache Software Foundation.</p>
</div>
</div>
</footer>
<script>
if(anchors) {
anchors.add();
}
</script>
</body>
</html>