Skip to content

Instantly share code, notes, and snippets.

@kdgregory
Created December 9, 2023 15:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kdgregory/202222cf23a9df085446f0f130da80de to your computer and use it in GitHub Desktop.
Save kdgregory/202222cf23a9df085446f0f130da80de to your computer and use it in GitHub Desktop.
Utility to merge Log4j2Plugins.dat files

This program is based on my reading of the Log4J source code from tag rel/2.21.0. It produces the same output for my Log4J2 example as the official transformer plugin, but I make no guarantees as to whether it will do so for any other version of Log4J.

import java.io.FileOutputStream;
import java.net.URL;
import java.util.Enumeration;
import org.apache.logging.log4j.core.config.plugins.processor.PluginCache;
/**
* A utility to combine the Log4j2Plugins.dat files from multiple JARs on the
* classpath, writing the output to the current working directory.
*/
public class CombinePluginFiles
{
public static void main(String[] args)
throws Exception
{
System.out.println("running");
Enumeration<URL> datFiles = Thread.currentThread().getContextClassLoader().getResources("META-INF/org/apache/logging/log4j/core/config/plugins/Log4j2Plugins.dat");
PluginCache cache = new PluginCache();
cache.loadCacheFiles(datFiles);
try (FileOutputStream out = new FileOutputStream("Log4j2Plugins.dat"))
{
cache.writeCache(out);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment