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, &quot;Benson Margulies&quot; &lt;<a href=3D"mailto:benson@basistech.=
com">[email protected]</a>&gt; 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 &lt;<a hre=
f=3D"mailto:[email protected]">[email protected]</a>&gt; =
wrote:<br>
&gt; Actually, Configurator.setLevel(<wbr>loggerName, level) does all that =
for you.<br>
<br>
Yes, and it it returned the old level, I wouldn&#39;t have needed to start<=
br>
this thread.<br>
<br>
&gt;<br>
&gt; Ralph<br>
&gt;<br>
&gt;&gt; On Nov 8, 2016, at 7:10 AM, Benson Margulies &lt;<a href=3D"mailto=
:[email protected]">[email protected]</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; 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>
&gt;&gt; is how I got into the neighborhood of<br>
&gt;&gt;<br>
&gt;&gt; org.apache.logging.log4j.core.<wbr>config.Configurator.setLevel<br=
>
&gt;&gt;<br>
&gt;&gt; I can follow your recipe instead.<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; On Tue, Nov 8, 2016 at 9:05 AM, Ralph Goers &lt;<a href=3D"mailto:=
[email protected]">[email protected]</a>&gt; wrote:<br>
&gt;&gt;&gt; Are you looking at the Logger or LoggerConfig.=C2=A0 Log4j 2 s=
eparates Loggers from their configuration.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; To modify a logLevel you need to do:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; LoggerContext context =3D (LoggerContext) LogManager.getContex=
t(false);<br>
&gt;&gt;&gt; Configuration config =3D context.getConfiguration();<br>
&gt;&gt;&gt; LoggerConfig loggerConfig =3D config.getLoggerConfig(<wbr>logg=
erName);<br>
&gt;&gt;&gt; loggerConfig.setLevel(level);<br>
&gt;&gt;&gt; context.updateLoggers();<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; 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>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Ralph<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; On Nov 8, 2016, at 6:51 AM, Benson Margulies &lt;<a href=
=3D"mailto:[email protected]">[email protected]</a>&gt; wrote:<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; In old log4j, I&#39;ve=C2=A0 maintained a JUnit rule that =
temporarily throttles a logger.<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; In log4j2, I see a setLevel, but no getLevel, which rather=
 screws up<br>
&gt;&gt;&gt;&gt; &#39;temporarily&#39;.<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; What am I missing?<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;<br>
&gt;<br>
&gt;<br>
</blockquote></div></div>

--001a1134fbceea3cee0540cc6dfd--