Are you really sure you want to get the Loggers?  Changing the logging level of 
a Logger doesn’t really work by itself. You really need to change the level of 
its associated LoggerConfig. If you need a LoggerConfig that actually matches 
the Logger’s name, and one doesn’t already exist, then you need to create one 
and add it to the configuration. You would then call updateLoggers to have it 
take effect.

Ralph

> On Nov 30, 2016, at 3:40 AM, Marcel Stör <[email protected]> wrote:
> 
> On 29.11.16 05:31, Matt Sicker wrote:
>> You could use the log4j-core implementation of LoggerContext.getLoggers()
>> to list the current known loggers.
>> https://logging.apache.org/log4j/2.x/log4j-core/apidocs/org/apache/logging/log4j/core/LoggerContext.html#getLoggers()
> 
> Yep, that was also suggested in one of the SO answers in my initial
> post. I currently implemented it that way. However,
> LoggerContext#getLoggers() does not return parent loggers. So, if the
> configuration is like
> 
> <Logger name="com.company" level="debug"/>
> <Root level="info">
>    <AppenderRef ref="CONSOLE"/>
> </Root>
> 
> I'd get all com.company.* loggers but neither the com.company logger nor
> the root logger. I could recursively traverse that list and call
> getParent() on each entry (and clean duplicates) to eventually arrive at
> the complete set.
> 
>> You could also use the JMX API for LoggerConfigAdminMBean to query the list
>> of loggers. You could look at the log4j-jmx-gui source code for ideas.
> 
> It uses ctx.getConfiguration().getLoggers() which, although called
> getLoggers(), actually returns logger configs.
> 
> My conclusion is that the quickest way to obtain the complete set is to
> combine the results of LoggerContext#getLoggers() and
> LoggerContext#getConfiguration()#getLoggers(). The fact that the data
> types of course "don't match" is not relevant as I just the name of each
> anyway.
> 
> -- 
> Marcel Stör, http://frightanic.com
> Couchsurfing: http://www.couchsurfing.com/people/marcelstoer
> O< ascii ribbon campaign - stop html mail - http://j.mp/1OThh9L
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to