> On Sep 27, 2020, at 11:07 AM, Jochen Wiedmann <[email protected]> 
> wrote:
> 
> On Sun, Sep 27, 2020 at 6:38 PM Ralph Goers <[email protected]> 
> wrote:
>> 
>> It would not create a new LoggerContext. But a ConfigurationSource 
>> represents an entire configuration. So calling initialize with it would 
>> cause a new Configuration to be created. So yes, all your existing 
>> LoggerConfigs would be replaced by the new configuration.  Loggers would be 
>> unaffected as those are created by the application calling 
>> LogManager.getLogger().
> 
> Okay, but in my particular case, I am not using
> LogManager.getLogger(), but loggerContext.getLogger(), because I have
> multiple LoggerContext instances. (Think of a shared manager, which
> provides logging for all web applications in a web server.)
> 
> So, the loggers are, in fact, tied to a particular LoggerContext,
> which I don't want to lose. Question remains: How can I change a given
> LoggerContect, if I have a ConfigurationSource?

Your question doesn’t make sense for a few reasons.

LoggerContext.getLogger() returns a Logger. These are Loggers that were created 
by calling LogManager.getLogger(name). These loggers are unaffected by 
configuration changes. You can reconfigure to your hearts content and these 
loggers won’t go anywhere because they are permanently attached to the 
LoggerContext. 
The LoggerContext references a Configuration object that contains all the 
Appenders, Layouts, Filters, and LoggerConfig objects that are created when the 
configuration is processed. Loggers are associated with LoggerConfigs when 
LoggerContext’s updateLoggers() is called.
A ConfigurationSource contains the URI or File reference to the textual form of 
a complete configuration. So it contains all the Appender, Layout, Filter and 
LoggerConfig definitions. 

So if you have a ConfigurationSource you can only change the full Configuration 
by calling Configurator.initialize(). 

 If you have manually updated the Configuration by adding new LoggerConfig 
objects you would call updateLoggers() to have it evaluate all the Loggers and 
match them against the appropriate LoggerConfigs.

Note that in your original question you said "I understand, that this method 
provides the means to change the logging configuration at runtime.”. That 
statement isn’t quite accurate. As I alluded to in the previous paragraph, 
updateLoggers() doesn’t really change the configuration. It causes the 
configuration to be reapplied to all the Loggers, thus making sure each points 
to the appropriate LoggerConfig. Presumably the Configuration was already 
changed by the time updateLoggers() is called.

Ralph



Reply via email to