Re: dynamic logging control
Ralph Goers <[email protected]> Tue, 8 Nov 2016 07:33:06 -0700
| Newsgroups | gmane.comp.apache.logging |
|---|---|
| Message-ID | <[email protected]> |
Actually, Configurator.setLevel(loggerName, level) does all that for = you. Ralph > On Nov 8, 2016, at 7:10 AM, Benson Margulies <[email protected]> = wrote: >=20 > I read http://logging.apache.org/log4j/2.x/manual/migration.html which > is how I got into the neighborhood of >=20 > org.apache.logging.log4j.core.config.Configurator.setLevel >=20 > I can follow your recipe instead. >=20 >=20 >=20 > On Tue, Nov 8, 2016 at 9:05 AM, Ralph Goers = <[email protected]> wrote: >> Are you looking at the Logger or LoggerConfig. Log4j 2 separates = Loggers from their configuration. >>=20 >> To modify a logLevel you need to do: >>=20 >> LoggerContext context =3D (LoggerContext) = LogManager.getContext(false); >> Configuration config =3D context.getConfiguration(); >> LoggerConfig loggerConfig =3D config.getLoggerConfig(loggerName); >> loggerConfig.setLevel(level); >> context.updateLoggers(); >>=20 >> This process locates the configured Logger for the desired logger = name, sets its level and then modifies all the Loggers that use the = LoggerConfig. >>=20 >> Ralph >>=20 >>> On Nov 8, 2016, at 6:51 AM, Benson Margulies <[email protected]> = wrote: >>>=20 >>> In old log4j, I've maintained a JUnit rule that temporarily = throttles a logger. >>>=20 >>> In log4j2, I see a setLevel, but no getLevel, which rather screws up >>> 'temporarily'. >>>=20 >>> What am I missing? >>>=20 >>=20 >>=20 >=20