At runtime I often create/modify log4j Loggers, Appenders, Levels, Layouts, and time to time need to reset everything back to defaults.
Log4j
Jan Zyka's solution pointed me in the right direction, but I'm using an XML configuration file rather than a properties files. Here is the code that worked for me:
LogManager.resetConfiguration(); // clear any existing config first
LoggerRepository loggerRepository = LogManager.getLoggerRepository();
DOMConfigurator domConfigurator = new DOMConfigurator();
try (
InputStream is = MyClassName.class.getResourceAsStream("/log4j.xml");
) {
domConfigurator.doConfigure(is, loggerRepository);
}
LOGGER.info("abc123");
I get a properly formatted log4j log entry with "abc123" as the log message.