How to get various loggers in log4j?

If my log4j.properties look this

# General configuration
log4j.rootLogger = ERROR, ConsoleAppender

# Appender configuration
log4j.appender.ConsoleAppender = org.apache.log4j.ConsoleAppender
log4j.appender.ConsoleAppender.layout = org.apache.log4j.PatternLayout 
log4j.appender.ConsoleAppender.layout.ConversionPattern = %5p (%c) %m%n
#Other Loggers
log4j.logger.com.foo=INFO
log4j.logger.com.foo.Bar=DEBUG
log4j.logger.org.springframework=INFO

Is there an easy way to get only the registrars com.foo, com.foo.Bar, rootand org.springframework. And not the specific classes that were created and inherit the levels (IE com.foo.bar.Baz?
For my purposes, I want to create an admin page that displays these registrars and their levels, but not ALL registrars, only those that were directly configured through the properties. Currently, I I look through the parent hierarchy until I am on the registrar with a different level, which is its parent, but which can hide some configured logs, if they are in the hierarchy, and set the same level as above.

+5
source share
1

- . :

Enumeration<Category> loggers = LogManager.getCurrentLoggers();

:

Level currentLevel = logger.getLevel();

currentLevel null, . , log4j.properties, . null. , . , log4j.properties.

, - setLevel() , . , log4j , , . , log4j.properties.

, , , . , com.foo.Bar , , log4j.properties. Log4J , . , log4j.properties.

+4

All Articles