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, &quot;Ralph Goers&quot; &lt;<a href=3D"mailto:ralph.goers@dslextreme=
.com">[email protected]</a>&gt; 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>
&gt; On Nov 8, 2016, at 7:13 AM, Benson Margulies &lt;<a href=3D"mailto:ben=
[email protected]">[email protected]</a>&gt; wrote:<br>
&gt;<br>
&gt; The need to add xml-apis to the dependency tree was also a bit of a su=
rprise.<br>
&gt;<br>
&gt;<br>
&gt; On Tue, Nov 8, 2016 at 9:10 AM, Benson Margulies &lt;<a href=3D"mailto=
:[email protected]">[email protected]</a>&gt; wrote:<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;<br>
<br>
<br>
</blockquote></div></div>

--94eb2c05e830cda4160540cb33c0--