You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Apostolis Giannakidis <ap...@gmail.com> on 2016/01/25 14:15:34 UTC

Multiple LoggerContext instances

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
Configurator.initialize()?

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
classloader.

Thank you very much for your valuable feedback,
Apostolis