There are two ways to get log4j2 to find your custom plugin: through the package configuration attribute and through the plugins data file created by javac.
Option 1: Package Attribute
There was an old version of log4j2 where the package attribute no longer worked, but this one was fixed in version 2.0.1. This should no longer be a problem.
To use this parameter, put the package name of your plugin class in the packages attribute. For example, if the fully qualified class name of your plugin is com.mycompany.myproduct.MyPlugin , run the log4j2.xml configuration file using
<Configuration status="trace" packages="com.mycompany.myproduct"> ...
The status="trace" attribute will display the log4j2 internal debugging commands displayed on the console. This can help fix any problems, for example, if your plugin is not found.
Option 2: plugin file
If you compile the log4j-core kernel in the classpath, javac will generate the log4j2 plugin data file. Maven will automatically include this in your jar, but if you are not using maven, you can manually include this file in your jar. Again, use status = "trace" to troubleshoot if necessary.
Configuration
After you have completed one of the above actions, log4j2 can find your plugin. The next step is to configure the plugin correctly. Perhaps this is causing the problem.
Suppose your plugin is a regular search and looks like this:
package com.mycompany.myproduct; @Plugin(name = "FabLookup", category = StrLookup.CATEGORY) public class BetterLookup extends AbstractLookup { @Override public String lookup(final LogEvent event, final String key) { return com.mycompany.SomeClass.getValue(key); } }
Now you have declared the name of your FabLookup plugin, so this is what you need to use in the configuration. Not the name of the class (although everything is the same for them).
An example configuration using your plugin will look like this:
<Configuration status="trace" packages="com.mycompany.myproduct"> ... <Appenders> <RollingFile name="RollingFile" fileName="logs/app.log" filePattern="logs/$${date:yyyy-MM}/app-%d{MM-dd-yyyy}.log.gz"> <PatternLayout header="${FabLookup:key1} ${FabLookup:key2}"> <Pattern>%d %m%n</Pattern> </PatternLayout> <Policies> <TimeBasedTriggeringPolicy /> </Policies> </RollingFile> ...
If the above is not enough to solve the problem, write in a little more detail, for example, how your plugin is declared in your java code and how it is configured in your log4j2.xml.