Why do you want to set the level on the LoggerConfig and all its descendants? 
Setting the level just on the LoggerConfig will achieve the same thing, so long 
as none of its descendants has a LoggerConfig

Sent from my iPad

> On Aug 15, 2015, at 8:25 AM, Gary Gregory <garydgreg...@gmail.com> wrote:
> 
> Let's say I have a logger tree like:
> 
> R
> R.P
> R.P.C1
> R.P.C1.L1
> R.P.C2.L2
> R.P.C2
> R.P.C2.L1
> R.P.C2.L2
> 
> and I want to set R.P.C2 and all it's descendants to a given level.
> 
> In Log4j 1.2, I do:
> 
>     public static void setChildren(final Logger parentLogger, final Level 
> newLevel) {
>         final Enumeration<Logger> enumeration = 
> LogManager.getCurrentLoggers();
>         while (enumeration.hasMoreElements()) {
>             final Logger logger = enumeration.nextElement();
>             if (LoggerUtils.isChild(parentLogger, logger)) {
>                 logger.setLevel(newLevel);
>             }
>         }
>     }
> 
>     private static boolean isChild(final Logger parentCandidate, final Logger 
> childCandidate) {
>         for (Category c = childCandidate; c != null; c = c.getParent()) {
>             if (c.equals(parentCandidate)) {
>                 return true;
>             }
>         }
>         return false;
>     }
> 
> I suppose I could determine parent/child with a startWith on the logger name 
> too.
> 
> I there a better way to do this with the Core in v2 aside from iterating over 
> all loggers in a context and doing a kind of isChild()? Can additivity be 
> used for this?
> 
> I'd like to add such a utility method to Configurator.
> 
> Gary
> 
> -- 
> E-Mail: garydgreg...@gmail.com | ggreg...@apache.org 
> Java Persistence with Hibernate, Second Edition
> JUnit in Action, Second Edition
> Spring Batch in Action
> Blog: http://garygregory.wordpress.com 
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory

Reply via email to