Re: dynamic logging control
Gary Gregory <[email protected]> Tue, 8 Nov 2016 08:14:04 -0800
| Newsgroups | gmane.comp.apache.logging |
|---|---|
| Message-ID | <CACZkXPw=6aXezrJFtz7qKbqg-0v6mq3LqrxSfeSYLQoSUKo1Dw@mail.gmail.com> |
--001a1134fbceea3cee0540cc6dfd Content-Type: text/plain; charset=UTF-8 Maybe we need to publicize the Configuator class a little better? Gary On Nov 8, 2016 7:51 AM, "Benson Margulies" <[email protected]> wrote: > On Tue, Nov 8, 2016 at 9:33 AM, Ralph Goers <[email protected]> > wrote: > > Actually, Configurator.setLevel(loggerName, level) does all that for > you. > > Yes, and it it returned the old level, I wouldn't have needed to start > this thread. > > > > > Ralph > > > >> On Nov 8, 2016, at 7: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? > >>>> > >>> > >>> > >> > > > > > --001a1134fbceea3cee0540cc6dfd Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <p dir=3D"ltr">Maybe we need to publicize the Configuator class a little be= tter?</p> <p dir=3D"ltr">Gary</p> <div class=3D"gmail_extra"><br><div class=3D"gmail_quote">On Nov 8, 2016 7:= 51 AM, "Benson Margulies" <<a href=3D"mailto:benson@basistech.= com">[email protected]</a>> wrote:<br type=3D"attribution"><blockquot= e class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc sol= id;padding-left:1ex">On Tue, Nov 8, 2016 at 9:33 AM, Ralph Goers <<a hre= f=3D"mailto:[email protected]">[email protected]</a>> = wrote:<br> > Actually, Configurator.setLevel(<wbr>loggerName, level) does all that = for you.<br> <br> Yes, and it it returned the old level, I wouldn't have needed to start<= br> this thread.<br> <br> ><br> > Ralph<br> ><br> >> On Nov 8, 2016, at 7:10 AM, Benson Margulies <<a href=3D"mailto= :[email protected]">[email protected]</a>> wrote:<br> >><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> --001a1134fbceea3cee0540cc6dfd--