Report this

What is the reason for this report?

Deep clone RollingFileAppender object

Posted on December 17, 2021

I am using log4j2 with XML based configuration (log4j2.xml). I have a RollingFileAppender defined in log4j2.xml, whose instances are created and attached to loggers dynamically based on certain logger functionality in my application. Every time to add an appender, I want to clone existing RollingFileAppender, just by changing file name. So, I am looking for the best way to deep clone RollingFileAppender (with all filters, pattern, policies etc.). I know I can use third party libraries to clone, but that needs certain JDK modules to be opened for reflective access which I want to avoid if possible. Is there a better way (maybe passing XML tag <RollingFile>…</RollingFile> and getting corresponding object from it?)

Any help would be highly appreciated. NOTE: I want to keep RollingFileAppender configuration externalized into log4j2.xml, avoiding to manage it into java code.

Thanks in advance.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.