blob: bee3f62f36a277bc80267c68f42ae853471fb697 [file] [log] [blame]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- Generated by Apache Maven Doxia at 2017-11-19 -->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Log4j &#x2013; Log4j 2 Plugins - Apache Log4j 2</title>
<link rel="stylesheet" href="../css/bootstrap.min.css" type="text/css" />
<link rel="stylesheet" href="../css/site.css" type="text/css" />
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/bootstrap.min.js"></script>
<script type="text/javascript" src="../js/prettify.min.js"></script>
<script type="text/javascript" src="../js/site.js"></script>
<meta name="author" content="Ralph Goers" />
<meta name="author" content="Matt Sicker" />
<meta name="Date-Revision-yyyymmdd" content="20171119" />
<meta http-equiv="Content-Language" content="en" />
</head>
<body class="composite">
<a href="https://logging.apache.org/">
<img class="logo-left" src="../images/ls-logo.jpg" alt="Apache logging services logo" />
</a>
<img class="logo-right" src="../images/logo.png" alt="Apache log4j logo" />
<div class="clear"></div>
<div class="navbar">
<div class="navbar-inner">
<div class="container-fluid">
<a class="brand" href="https://logging.apache.org/log4j/2.x/">Apache Log4j 2 &trade;</a>
<ul class="nav">
<li>
<a href="https://wiki.apache.org/logging" class="external" target="_blank" title="Logging Wiki">Logging Wiki</a>
</li>
<li>
<a href="https://www.apache.org/" class="external" target="_blank" title="Apache">Apache</a>
</li>
<li>
<a href="../../../" title="Logging Services">Logging Services</a>
</li>
<li>
<a href="https://analysis.apache.org/dashboard/index/org.apache.logging.log4j:log4j" class="external" target="_blank" title="Sonar">Sonar</a>
</li>
<li>
<a href="https://github.com/apache/logging-log4j2" class="external" target="_blank" title="GitHub">GitHub</a>
</li>
</ul>
</div>
</div>
</div>
<div class="container-fluid">
<table class="layout-table">
<tr>
<td class="sidebar">
<div class="well sidebar-nav">
<ul class="nav nav-list">
<li class="nav-header"><i class="icon-home"></i>Apache Log4j™ 2</li>
<li class="none">
<a href="../index.html" title="About">About</a>
</li>
<li class="none">
<a href="../download.html" title="Download">Download</a>
</li>
<li class="collapsed">
<a href="../javadoc.html" title="Javadoc">Javadoc</a>
</li>
<li class="none">
<a href="../maven-artifacts.html" title="Maven, Ivy, Gradle Artifacts">Maven, Ivy, Gradle Artifacts</a>
</li>
<li class="none">
<a href="../runtime-dependencies.html" title="Runtime Dependencies">Runtime Dependencies</a>
</li>
<li class="none">
<a href="../changelog.html" title="Changelog">Changelog</a>
</li>
<li class="none">
<a href="../faq.html" title="FAQ">FAQ</a>
</li>
<li class="collapsed">
<a href="../performance.html" title="Performance">Performance</a>
</li>
<li class="none">
<a href="../articles.html" title="Articles and Tutorials">Articles and Tutorials</a>
</li>
<li class="none">
<a href="../thanks.html" title="Thanks">Thanks</a>
</li>
</ul>
<ul class="nav nav-list">
<li class="nav-header"><i class="icon-pencil"></i>For Contributors</li>
<li class="none">
<a href="../build.html" title="Building Log4j from Source">Building Log4j from Source</a>
</li>
<li class="none">
<a href="../guidelines.html" title="Guidelines">Guidelines</a>
</li>
<li class="none">
<a href="../javastyle.html" title="Style Guide">Style Guide</a>
</li>
</ul>
<ul class="nav nav-list">
<li class="nav-header"><i class="icon-book"></i>Manual</li>
<li class="none">
<a href="../manual/index.html" title="Introduction">Introduction</a>
</li>
<li class="none">
<a href="../manual/architecture.html" title="Architecture">Architecture</a>
</li>
<li class="none">
<a href="../manual/migration.html" title="Log4j 1.x Migration">Log4j 1.x Migration</a>
</li>
<li class="collapsed">
<a href="../manual/api.html" title="Java API">Java API</a>
</li>
<li class="none">
<a href="../manual/scala-api.html" title="Scala API">Scala API</a>
</li>
<li class="collapsed">
<a href="../manual/configuration.html" title="Configuration">Configuration</a>
</li>
<li class="collapsed">
<a href="../manual/webapp.html" title="Web Applications and JSPs">Web Applications and JSPs</a>
</li>
<li class="collapsed">
<a href="../manual/lookups.html" title="Lookups">Lookups</a>
</li>
<li class="collapsed">
<a href="../manual/appenders.html" title="Appenders">Appenders</a>
</li>
<li class="collapsed">
<a href="../manual/layouts.html" title="Layouts">Layouts</a>
</li>
<li class="collapsed">
<a href="../manual/filters.html" title="Filters">Filters</a>
</li>
<li class="collapsed">
<a href="../manual/async.html" title="Async Loggers">Async Loggers</a>
</li>
<li class="collapsed">
<a href="../manual/garbagefree.html" title="Garbage-free Logging">Garbage-free Logging</a>
</li>
<li class="none">
<a href="../manual/jmx.html" title="JMX">JMX</a>
</li>
<li class="none">
<a href="../manual/logsep.html" title="Logging Separation">Logging Separation</a>
</li>
<li class="collapsed">
<a href="../manual/extending.html" title="Extending Log4j">Extending Log4j</a>
</li>
<li class="expanded active">
<a href="../manual/plugins.html" title="Plugins">Plugins</a>
<ul>
<li class="none">
<a href="../manual/plugins.html#Core" title="Core">Core</a>
</li>
<li class="none">
<a href="../manual/plugins.html#Converters" title="Converters">Converters</a>
</li>
<li class="none">
<a href="../manual/plugins.html#KeyProviders" title="Key Providers">Key Providers</a>
</li>
<li class="none">
<a href="../manual/plugins.html#Lookups" title="Lookups">Lookups</a>
</li>
<li class="none">
<a href="../manual/plugins.html#TypeConverters" title="Type Converters">Type Converters</a>
</li>
<li class="none">
<a href="../manual/plugins.html#DeveloperNotes" title="Developer Notes">Developer Notes</a>
</li>
</ul>
</li>
<li class="collapsed">
<a href="../manual/customconfig.html" title="Programmatic Log4j Configuration">Programmatic Log4j Configuration</a>
</li>
<li class="collapsed">
<a href="../manual/customloglevels.html" title="Custom Log Levels">Custom Log Levels</a>
</li>
</ul>
<ul class="nav nav-list">
<li class="nav-header"><i class="icon-tags"></i>Related Projects</li>
<li class="none">
<a href="http://logging.apache.org/log4j/scala/index.html" class="external" target="_blank" title="Log4j-Scala">Log4j-Scala</a>
</li>
</ul>
<ul class="nav nav-list">
<li class="nav-header"><i class="icon-tags"></i>Legacy</li>
<li class="none">
<a href="http://logging.apache.org/log4j/1.2/" class="external" target="_blank" title="Log4j 1.2">Log4j 1.2</a>
</li>
<li class="none">
<a href="http://logging.apache.org/log4j/log4j-2.3/" class="external" target="_blank" title="Log4j 2.3">Log4j 2.3</a>
</li>
</ul>
<ul class="nav nav-list">
<li class="nav-header"><i class="icon-cog"></i>Components</li>
<li class="none">
<a href="../log4j-api/index.html" title="API">API</a>
</li>
<li class="none">
<a href="../log4j-core/index.html" title="Implementation">Implementation</a>
</li>
<li class="none">
<a href="../log4j-jcl/index.html" title="Commons Logging Bridge">Commons Logging Bridge</a>
</li>
<li class="none">
<a href="../log4j-1.2-api/index.html" title="Log4j 1.2 API">Log4j 1.2 API</a>
</li>
<li class="none">
<a href="../log4j-slf4j-impl/index.html" title="SLF4J Binding">SLF4J Binding</a>
</li>
<li class="none">
<a href="../log4j-jul/index.html" title="JUL Adapter">JUL Adapter</a>
</li>
<li class="none">
<a href="../log4j-to-slf4j/index.html" title="Log4j 2 to SLF4J Adapter">Log4j 2 to SLF4J Adapter</a>
</li>
<li class="none">
<a href="../log4j-flume-ng/index.html" title="Apache Flume Appender">Apache Flume Appender</a>
</li>
<li class="none">
<a href="../log4j-taglib/index.html" title="Log4j Tag Library">Log4j Tag Library</a>
</li>
<li class="none">
<a href="../log4j-jmx-gui/index.html" title="Log4j JMX GUI">Log4j JMX GUI</a>
</li>
<li class="none">
<a href="../log4j-web/index.html" title="Log4j Web Application Support">Log4j Web Application Support</a>
</li>
<li class="none">
<a href="../log4j-appserver/index.html" title="Log4j Application Server Integration">Log4j Application Server Integration</a>
</li>
<li class="none">
<a href="../log4j-couchdb/index.html" title="Log4j CouchDB appender">Log4j CouchDB appender</a>
</li>
<li class="none">
<a href="../log4j-mongodb/index.html" title="Log4j MongoDB appender">Log4j MongoDB appender</a>
</li>
<li class="none">
<a href="../log4j-cassandra/index.html" title="Log4j Cassandra appender">Log4j Cassandra appender</a>
</li>
<li class="none">
<a href="../log4j-iostreams/index.html" title="Log4j IO Streams">Log4j IO Streams</a>
</li>
<li class="none">
<a href="../log4j-liquibase/index.html" title="Log4j Liquibase Binding">Log4j Liquibase Binding</a>
</li>
</ul>
<ul class="nav nav-list">
<li class="nav-header"><i class="icon-info-sign"></i>Project Information</li>
<li class="none">
<a href="../dependencies.html" title="Dependencies">Dependencies</a>
</li>
<li class="none">
<a href="../dependency-convergence.html" title="Dependency Convergence">Dependency Convergence</a>
</li>
<li class="none">
<a href="../dependency-management.html" title="Dependency Management">Dependency Management</a>
</li>
<li class="none">
<a href="../team-list.html" title="Project Team">Project Team</a>
</li>
<li class="none">
<a href="../mail-lists.html" title="Mailing Lists">Mailing Lists</a>
</li>
<li class="none">
<a href="../issue-tracking.html" title="Issue Tracking">Issue Tracking</a>
</li>
<li class="none">
<a href="../license.html" title="Project License">Project License</a>
</li>
<li class="none">
<a href="../source-repository.html" title="Source Repository">Source Repository</a>
</li>
<li class="none">
<a href="../project-summary.html" title="Project Summary">Project Summary</a>
</li>
</ul>
<ul class="nav nav-list">
<li class="nav-header"><i class="icon-cog"></i>Project Reports</li>
<li class="none">
<a href="../changes-report.html" title="Changes Report">Changes Report</a>
</li>
<li class="none">
<a href="../jira-report.html" title="JIRA Report">JIRA Report</a>
</li>
<li class="none">
<a href="../surefire-report.html" title="Surefire Report">Surefire Report</a>
</li>
<li class="none">
<a href="../rat-report.html" title="RAT Report">RAT Report</a>
</li>
</ul>
</div>
<div id="poweredBy">
<a href="http://maven.apache.org/" title="Built by Maven" class="poweredBy">
<img class="poweredBy" alt="Built by Maven" src="../images/maven-feather.png" />
</a>
</div>
</td>
<td class="content">
<!-- Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. -->
<div class="section">
<h2><a name="Plugins"></a>Plugins</h2>
<div class="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 <tt>PluginManager</tt> 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 <tt>BundleListener</tt>
is added on activation to continue checking new bundles after <tt>log4j-core</tt> has started.</li>
<li>A comma-separated list of packages specified by the <tt>log4j.plugin.packages</tt>
system property.</li>
<li>Packages passed to the static <tt>PluginManager.addPackages</tt> method (before Log4j configuration
occurs).</li>
<li>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) <tt>name</tt>, then the load order above
determines which one will be used. For example, to override the <tt>File</tt> plugin which is provided
by the built-in <tt>FileAppender</tt> class, you would need to place your plugin in a JAR file in the
CLASSPATH ahead of<tt>log4j-core.jar</tt>. 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="http://www.osgi.org/javadoc/r5/core/org/osgi/framework/BundleContext.html#getBundles()">getBundles()</a>
and
<a class="javadoc" href="http://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.
<!-- TODO: in future, plugins will be able to be annotated with @Order which can override priorities -->
</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,
<tt>org.apache.logging.log4j.core.config.plugins.processor.PluginProcessor</tt>. 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>
</div>
<div class="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 <tt>@PluginFactory</tt> or
<tt>@PluginBuilderFactory</tt>. The former is used for static factory methods that provide all options
as method parameters, and the latter is used to construct a new <tt>Builder&lt;T&gt;</tt> class whose
fields are used for injecting attributes and child nodes. To allow the <tt>Configuration</tt> 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 <tt>FileAppender</tt>). See <a href="extending.html#Plugin_Builders">Extending
Log4j with Plugin Builders</a> for more details.
</p>
<div class="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 <tt>TypeConverter</tt> plugins may also be
provided for more type support. Note that <tt>PluginBuilderAttribute</tt> 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 <tt>Configuration</tt> 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 <tt>Node</tt> 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 <tt>Node</tt> or its attribute named <tt>value</tt>.</dd>
</dl>
</div>
<div class="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="http://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 <tt>null</tt> as well
as several other scenarios: empty <tt>CharSequence</tt> objects, empty arrays, empty <tt>Collection</tt>
instances, and empty <tt>Map</tt> 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="http://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>
</div></div>
<div class="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 <tt>@Plugin</tt> annotation, have a static <tt>newInstance</tt> method that
accepts an array of <tt>String</tt>s as its only parameter and returns an instance of the Converter, and
must have a <tt>@ConverterKeys</tt> annotation present that contains the array of converter patterns
that will cause the Converter to be selected. Converters that are meant to handle <tt>LogEvent</tt>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 <tt>LogEvent</tt> and a <tt>StringBuilder</tt>
as arguments. The Converter should append the result of its operation to the <tt>StringBuilder</tt>.
</p>
<p>
A second type of Converter is the FileConverter - which must have &quot;FileConverter&quot; specified in the
category attribute of the <tt>@Plugin</tt> annotation. While similar to a <tt>LogEventPatternConverter</tt>,
instead of a single format method these Converters will have two variations; one that takes an
<tt>Object</tt> and one that takes an array of <tt>Object</tt>s instead of the <tt>LogEvent</tt>.
Both append to the provided <tt>StringBuilder</tt> in the same fashion as a <tt>LogEventPatternConverter</tt>.
These Converters are typically used by the <tt>RollingFileAppender</tt> to construct the name of the
file to log to.
</p>
<p>
If multiple Converters specify the same <tt>ConverterKeys</tt>, then the load order above determines
which one will be used. For example, to override the <tt>%date</tt> converter which is provided by the
built-in <tt>DatePatternConverter</tt> class, you would need to place your plugin in a JAR file in the
CLASSPATH ahead of<tt>log4j-core.jar</tt>. 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>
</div>
<div class="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>
</div>
<div class="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>
</div>
<div class="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 <tt>@PluginElement</tt> annotation; now, any
type supported by the type conversion system can be used in a <tt>@PluginAttribute</tt> parameter.
Conversion of enum types are supported on demand and do not require custom <tt>TypeConverter</tt>
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 <tt>TypeConverter</tt> is purely cosmetic. Appropriate
type converters are looked up via the <tt>Type</tt> interface rather than via <tt>Class&lt;?&gt;</tt>
objects only. Do note that <tt>TypeConverter</tt> plugins must have a default constructor.
</p>
</div>
</div>
<div class="section">
<h2><a name="Developer_Notes"></a>Developer Notes</h2>
<a name="DeveloperNotes"></a>
<p>
If a plugin class implements
<a class="javadoc" href="http://docs.oracle.com/javase/6/docs/api/java/util/Collection.html">Collection</a> or
<a class="javadoc" href="http://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 <tt>Collection</tt> or <tt>Map</tt>.
</p>
</div>
</td>
</tr>
</table>
</div>
<div class="footer">
<p>Copyright &copy; 1999-2017 <a class="external" href="https://www.apache.org/">The Apache Software Foundation</a>. All Rights Reserved.</p>
<p>Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, and the Apache Logging project logo are trademarks of The Apache Software Foundation.</p>
<p>Site powered by <a class="external" href="http://getbootstrap.com/">Twitter Bootstrap</a>. Icons from <a class="external" href="http://glyphicons.com/">Glyphicons Free</a>.</p>
</div>
</div>
</body>
</html>