logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apostolis Giannakidis <ap.giannaki...@gmail.com>
Subject Multiple LoggerContext instances
Date Mon, 25 Jan 2016 13:15:34 GMT
Hello log4j team,

I have a use case where I need to create different loggers with different
attributes at run time.

For example, let's say that:
1) at startup I want 1 logger with 1 syslog appender
2) after a while, I want 1 logger with 1 file appender
3) after a while, I want 1 logger with 1 syslog and 1 file appender

What would be more suitable in this case?
a) programmatically modifying the current configuration after initialization
b) or creating a new configuration using the ConfigurationBuilder and
initializing a new LoggerContext for the new configuration using

Personally, I find the 2nd approach better as it provides a cleaner API to
programmatically create the new loggers. But by doing so, I will create
multiple LoggerContexts. Is it valid to have multiple LoggerContexts? If
yes, what is the recommended way of accessing the a LoggerContext? I am
aware about the ContextSelector class but I am not sure if it is suitable
for my needs, as all the LoggerContexts will be created using the same

Thank you very much for your valuable feedback,

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message