Re: dynamic logging control
Benson Margulies <[email protected]> Tue, 8 Nov 2016 09:46:14 -0500
| Newsgroups | gmane.comp.apache.logging |
|---|---|
| Message-ID | <CALm0H57=A_fQ9D2TpHusUhmS28YE7bGRPuquQdqKH=8VFC9mFQ@mail.gmail.com> |
--94eb2c05e830cda4160540cb33c0 Content-Type: text/plain; charset=UTF-8 ElementTraversal On Nov 8, 2016 9:34 AM, "Ralph Goers" <[email protected]> wrote: > What is xml-apis required for? If you need it then we have a problem. > > Ralph > > > On Nov 8, 2016, at 7:13 AM, Benson Margulies <[email protected]> > wrote: > > > > The need to add xml-apis to the dependency tree was also a bit of a > surprise. > > > > > > On Tue, Nov 8, 2016 at 9:10 AM, Benson Margulies <[email protected]> > wrote: > >> I read http://logging.apache.org/log4j/2.x/manual/migration.html which > >> is how I got into the neighborhood of > >> > >> org.apache.logging.log4j.core.config.Configurator.setLevel > >> > >> I can follow your recipe instead. > >> > >> > >> > >> 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. > >>> > >>> To modify a logLevel you need to do: > >>> > >>> LoggerContext context = (LoggerContext) LogManager.getContext(false); > >>> Configuration config = context.getConfiguration(); > >>> LoggerConfig loggerConfig = config.getLoggerConfig(loggerName); > >>> loggerConfig.setLevel(level); > >>> context.updateLoggers(); > >>> > >>> This process locates the configured Logger for the desired logger > name, sets its level and then modifies all the Loggers that use the > LoggerConfig. > >>> > >>> Ralph > >>> > >>>> On Nov 8, 2016, at 6:51 AM, Benson Margulies <[email protected]> > wrote: > >>>> > >>>> In old log4j, I've maintained a JUnit rule that temporarily > throttles a logger. > >>>> > >>>> In log4j2, I see a setLevel, but no getLevel, which rather screws up > >>>> 'temporarily'. > >>>> > >>>> What am I missing? > >>>> > >>> > >>> > > > > > --94eb2c05e830cda4160540cb33c0 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <p dir=3D"ltr">ElementTraversal<br> </p> <div class=3D"gmail_extra"><br><div class=3D"gmail_quote">On Nov 8, 2016 9:= 34 AM, "Ralph Goers" <<a href=3D"mailto:ralph.goers@dslextreme= .com">[email protected]</a>> wrote:<br type=3D"attribution"><bl= ockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #= ccc solid;padding-left:1ex">What is xml-apis required for? If you need it t= hen we have a problem.<br> <br> Ralph<br> <br> > On Nov 8, 2016, at 7:13 AM, Benson Margulies <<a href=3D"mailto:ben= [email protected]">[email protected]</a>> wrote:<br> ><br> > The need to add xml-apis to the dependency tree was also a bit of a su= rprise.<br> ><br> ><br> > On Tue, Nov 8, 2016 at 9:10 AM, Benson Margulies <<a href=3D"mailto= :[email protected]">[email protected]</a>> wrote:<br> >> I read <a href=3D"http://logging.apache.org/log4j/2.x/manual/migra= tion.html" rel=3D"noreferrer" target=3D"_blank">http://logging.apache.org/<= wbr>log4j/2.x/manual/migration.<wbr>html</a> which<br> >> is how I got into the neighborhood of<br> >><br> >> org.apache.logging.log4j.core.<wbr>config.Configurator.setLevel<br= > >><br> >> I can follow your recipe instead.<br> >><br> >><br> >><br> >> On Tue, Nov 8, 2016 at 9:05 AM, Ralph Goers <<a href=3D"mailto:= [email protected]">[email protected]</a>> wrote:<br> >>> Are you looking at the Logger or LoggerConfig.=C2=A0 Log4j 2 s= eparates Loggers from their configuration.<br> >>><br> >>> To modify a logLevel you need to do:<br> >>><br> >>> LoggerContext context =3D (LoggerContext) LogManager.getContex= t(false);<br> >>> Configuration config =3D context.getConfiguration();<br> >>> LoggerConfig loggerConfig =3D config.getLoggerConfig(<wbr>logg= erName);<br> >>> loggerConfig.setLevel(level);<br> >>> context.updateLoggers();<br> >>><br> >>> This process locates the configured Logger for the desired log= ger name, sets its level and then modifies all the Loggers that use the Log= gerConfig.<br> >>><br> >>> Ralph<br> >>><br> >>>> On Nov 8, 2016, at 6:51 AM, Benson Margulies <<a href= =3D"mailto:[email protected]">[email protected]</a>> wrote:<br> >>>><br> >>>> In old log4j, I've=C2=A0 maintained a JUnit rule that = temporarily throttles a logger.<br> >>>><br> >>>> In log4j2, I see a setLevel, but no getLevel, which rather= screws up<br> >>>> 'temporarily'.<br> >>>><br> >>>> What am I missing?<br> >>>><br> >>><br> >>><br> ><br> <br> <br> </blockquote></div></div> --94eb2c05e830cda4160540cb33c0--