Hello Matt,

this sounds great however it doesn't work.

Maybe it is a bug ?

what I do is :

 final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);

            Configuration cfg = ctx.getConfiguration();

            if (cfg instanceof XmlConfiguration) {

                //add logger if not added

                LoggerConfig logger = ((XmlConfiguration)
cfg).getLogger(loggerName);

                if (logger == null) {

                    logger = new LoggerConfig(loggerName, Level.DEBUG,
false); //here this false is for the additive

                    cfg.addLogger(loggerName, logger);

                } else { //change the level leave it as it is

                    logger.setLevel(Level.DEBUG);

                }

                logger.addAppender(newAppender, Level.DEBUG, null);

                ctx.updateLoggers(cfg);

}


Still .. all root loggers also receive the log message(s) together with
this new appender that is passed here.

I am using 2.0 final


On Jul 21, 2014 5:32 PM, "Matt Sicker" <[email protected]> wrote:

> You should specify false for additivity to prevent the automatic
> inheritance.
>
>
> On 21 July 2014 09:20, Nayden Gochev <[email protected]> wrote:
>
>> In short:
>> I am trying to add a custom appender + logger for some package for
>> example "org.test"
>> However the root appenders (appender refs) are always added as well
>> automatically.. so even if I have a root appender(s) with level INFO
>> defined in the log4j2.xml,
>> ones I add a logger with level DEBUG.. with a new appender (only 1) ..
>> the 2 root appenders that I have defined in the XML automatically starts
>> receiving this DEBUG messages as well.
>>
>> Is it possible somehow to REMOVE this ROOT appends.. from my newly
>> created logger ?
>> newLoggerConfig.getAppenderRefs().clear(); doesn't work of course :)
>>
>> Thanks for the help,
>> much appreciated.
>>
>
>
>
> --
> Matt Sicker <[email protected]>
>

Reply via email to