Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is an equivalent of LoggerRepository in log4j2

Tags:

java

log4j

log4j2

I want to migrate from Log4j 1.x to log4j2 so I read this article:

http://logging.apache.org/log4j/2.x/manual/migration.html

In our application we are using LoggerRepository:

Logger.getRootLogger().getLoggerRepository().getCurrentLoggers();

what is the equivalent of this piece of code in log4j2. Because in article they said we can't access to this method but they don't mention how should I replace it

like image 970
hudi Avatar asked Nov 11 '22 11:11

hudi


1 Answers

If I understand your need correctly, you can go via LogManager to get the LoggerContext's configuration and retrieve the Loggers from that:

LoggerContext ctx = LogManager.getContext();
Configuration cfg = ctx.getConfiguration();
Map<String, LoggerConfig> loggers = cfg.getLoggers();
like image 183
EvenLisle Avatar answered Nov 14 '22 22:11

EvenLisle