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.
Created
December 9, 2023 15:56
-
-
Save kdgregory/202222cf23a9df085446f0f130da80de to your computer and use it in GitHub Desktop.
Utility to merge Log4j2Plugins.dat files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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