Deep clone RollingFileAppender object

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.

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer