Volker, It looks like Configurator.setLevel(String loggerName, Level level) will do the same thing as the code below.
Ralph > On Feb 9, 2018, at 1:21 AM, Volker Weber <v.we...@inexso.de> wrote: > > Hi Mike, > > in our app we implemented a REST-Service to reconfigure log4j2 at runtime. > > It's mainly to apply changes to the configuration and call updateLoggers() > > LoggerContext loggerContext = (LoggerContext) > LogManager.getContext(false); > Configuration configuration = loggerContext.getConfiguration(); > LoggerConfig loggerConfig = configuration.getLoggerConfig(loggerName); > LoggerConfig specificConfig = loggerConfig; > > if (!loggerConfig.getName().equals(loggerName)) { > specificConfig = new LoggerConfig(loggerName, level, true); > specificConfig.setParent(loggerConfig); > configuration.addLogger(loggerName, specificConfig); > } > specificConfig.setLevel(level); > loggerContext.updateLoggers(); > > see attachment for our full Log4j2Util code. > > Regards, > Volker > > > > 2018-02-08 21:28 GMT+01:00 Mike Kienenberger <mkien...@gmail.com > <mailto:mkien...@gmail.com>>: > As others have reported in years past, the examples in the docs for > > Programmatically Modifying the Current Configuration after Initialization > > are out of date. They don't compile. They don't work (affect the > existing logging) even if you do fix the errors. > > Here's my situation: > > I am working in an environment with EVIL.JAR which includes a log4j2.xml file. > I can't change the jar. I can't specific a System Property to override it. > > My code gets called as a loaded module long after the logging system > is initialized. > > I want logging in my own code to go to a different location, and > preferably I'd like to read the configuration in from a log4j2.xml > file so that anyone who uses my module isn't victim to the same evil > hardcoded-logging practices of EVIL.JAR. > > Creating an XMLConfiguration and initializing it lets me read the xml > file easily enough. Looping through the data gets me the Appenders, > Filters and Loggers. But I still can't use them to modify the > existing configuration. > > Another person took the approach of using JUL instead. I hate JUL and > I'd really rather not have to go down that route. > > Thanks in advance. > -Mike > > --------------------------------------------------------------------- > To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org > <mailto:log4j-user-unsubscr...@logging.apache.org> > For additional commands, e-mail: log4j-user-h...@logging.apache.org > <mailto:log4j-user-h...@logging.apache.org> > > > > > -- > inexso - information exchange solutions GmbH > Ofener Straße 30 | 26121 Oldenburg > www.inexso.de <http://www.inexso.de/> > <Log4j2Util.java> > --------------------------------------------------------------------- > To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org > For additional commands, e-mail: log4j-user-h...@logging.apache.org