I'm trying to configure the pattern of the Root Logger using one of the log4j programatic api's. This is what I have, it's removing the default logger and I know that reconfigure, setLevel and setRootLevel are working, but the new ConsoleAppender isn't actually logging anything
private static void configureLog4j(Level rootLevel, Map<String, Level> levelMap) {
var pattern = PatternLayout.newBuilder().withPattern( "%highlight{[%t] %-5level: %msg%n%throwable}\n" ).build();
var console = ConsoleAppender.createDefaultAppenderForLayout( pattern );
var config = LoggerContext.getContext().getConfiguration();
config.addAppender( console );
var root = config.getRootLogger();
for ( var appenderRef : root.getAppenderRefs() ) {
root.removeAppender( appenderRef.getRef() );
}
root.addAppender( console, rootLevel, null );
Configurator.setRootLevel( rootLevel );
Configurator.setLevel( levelMap );
Configurator.reconfigure(config);
}
I tried the other API too, same luck there. How can I fix my code?
Here's a full link to my source, sorry, I've been working on it so the line number may change.