Return-Path: X-Original-To: apmail-logging-log4j-dev-archive@www.apache.org Delivered-To: apmail-logging-log4j-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C8B2D18B92 for ; Sat, 22 Aug 2015 16:25:44 +0000 (UTC) Received: (qmail 68922 invoked by uid 500); 22 Aug 2015 16:25:44 -0000 Delivered-To: apmail-logging-log4j-dev-archive@logging.apache.org Received: (qmail 68871 invoked by uid 500); 22 Aug 2015 16:25:44 -0000 Mailing-List: contact log4j-dev-help@logging.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Log4J Developers List" Reply-To: "Log4J Developers List" Delivered-To: mailing list log4j-dev@logging.apache.org Received: (qmail 68860 invoked by uid 99); 22 Aug 2015 16:25:44 -0000 Received: from Unknown (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 22 Aug 2015 16:25:44 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 2431D1AAA64 for ; Sat, 22 Aug 2015 16:25:44 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 2.901 X-Spam-Level: ** X-Spam-Status: No, score=2.901 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=3, URIBL_BLOCKED=0.001] autolearn=disabled Authentication-Results: spamd2-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-eu-west.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id fGrkYrXUynh0 for ; Sat, 22 Aug 2015 16:25:29 +0000 (UTC) Received: from mail-la0-f50.google.com (mail-la0-f50.google.com [209.85.215.50]) by mx1-eu-west.apache.org (ASF Mail Server at mx1-eu-west.apache.org) with ESMTPS id 8485E38552 for ; Sat, 22 Aug 2015 15:19:32 +0000 (UTC) Received: by laba3 with SMTP id a3so56109966lab.1 for ; Sat, 22 Aug 2015 08:19:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=h8h4Dhhal4bLyvXCeEPX4Ard7ARj5NywltVln5QEAXI=; b=gmUkYoEZQWrMgU52uVGgw0PeEQhjW80Rpq9mc5pq879/k7HwK6YioyfNzZwmxE0pyt LGbTNhz09lmVDD2IN8P7lY8Qabef+RGRrD839DpQcubQqCRys0KdzknbHobnxGnJSrc2 +I30CE7JO0Yi6DWikUZfalT5WiNZ4E/nWKKvWyeioBae5xJRyRH7YUVT+mBjXNVAw1TW nohrtXnNXsZ31ZSUNQEMlR5tPr8pzfN4cb9viRz1p2Kxwbomwid2Uukh5p9msXl/QyMv 4dwKz23XoeRjkoiEklvDcdgj8U+7bgjxN7cX/O4ebGyr5/6dtSUOC+03UmP+Q4JnXVGx Vwcw== MIME-Version: 1.0 X-Received: by 10.152.36.67 with SMTP id o3mr12472845laj.11.1440256766585; Sat, 22 Aug 2015 08:19:26 -0700 (PDT) Received: by 10.112.126.66 with HTTP; Sat, 22 Aug 2015 08:19:26 -0700 (PDT) In-Reply-To: <16E43D13-106F-455B-891E-633D559BD6BF@dslextreme.com> References: <2BB02CFE-62C9-4798-8339-3B6F0853D6B6@dslextreme.com> <16E43D13-106F-455B-891E-633D559BD6BF@dslextreme.com> Date: Sat, 22 Aug 2015 08:19:26 -0700 Message-ID: Subject: Re: setting the level for a logger tree From: Gary Gregory To: Log4J Developers List Content-Type: multipart/alternative; boundary=089e0158b78ef53291051de7e819 --089e0158b78ef53291051de7e819 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Let's say I have Logger com =3D ERROR (or even just the root Logger at ERROR). and I want Logger com.domain.foo and all its children set to DEBUG If I get the LoggerConfig that matches the parent logger and call setLevel on that, I will end up with Logger com at DEBUG, won't I? Gary On Fri, Aug 21, 2015 at 9:53 PM, Ralph Goers wrote: > That is definitely not how to implement it. > > You should get the LoggerConfig that matches your parent logger and call > setLevel on that. Then loop through all the loggerConfigs that start with > the located LoggerConfigs name and then call setLevel on them. You > typically aren=E2=80=99t going to have many LoggerConfigs while you could= have > thousands of Loggers, which all resolve to the same LoggerConfig. > > Ralph > > On Aug 21, 2015, at 9:30 PM, Gary Gregory wrote: > > On Wed, Aug 19, 2015 at 7:59 PM, Gary Gregory > wrote: > >> On Sat, Aug 15, 2015 at 3:56 PM, Gary Gregory >> wrote: >> >>> On Sat, Aug 15, 2015 at 3:07 PM, Ralph Goers >> > wrote: >>> >>>> Why do you want to set the level on the LoggerConfig and all its >>>> descendants? >>>> >>> >>> Because I clearly did not educate myself fully in this topic. ;-) Hence >>> I am looking for a shortcut by asking on the ML :-) >>> >>> >>>> Setting the level just on the LoggerConfig will achieve the same thing= , >>>> so long as none of its descendants has a LoggerConfig >>>> >>> >>> That's cool, but... How can I know if any descendant has a LoggerConfig= ? >>> How can do this generically? >>> >> >> Here is my proposal (including a test): >> https://issues.apache.org/jira/secure/attachment/12751400/log4j.diff >> >> I am not crazy about the API name: setChildren(String loggerName, Level >> level). >> >> Thoughts? >> > > Anyone? Bueller? :-) > > >> >> Gary >> >> >>> Gary >>> >>> >>>> >>>> Sent from my iPad >>>> >>>> On Aug 15, 2015, at 8:25 AM, Gary Gregory >>>> wrote: >>>> >>>> Let's say I have a logger tree like: >>>> >>>> R >>>> R.P >>>> R.P.C1 >>>> R.P.C1.L1 >>>> R.P.C2.L2 >>>> R.P.C2 >>>> R.P.C2.L1 >>>> R.P.C2.L2 >>>> >>>> and I want to set R.P.C2 and all it's descendants to a given level. >>>> >>>> In Log4j 1.2, I do: >>>> >>>> public static void setChildren(final Logger parentLogger, final >>>> Level newLevel) { >>>> final Enumeration enumeration =3D >>>> LogManager.getCurrentLoggers(); >>>> while (enumeration.hasMoreElements()) { >>>> final Logger logger =3D enumeration.nextElement(); >>>> if (LoggerUtils.isChild(parentLogger, logger)) { >>>> logger.setLevel(newLevel); >>>> } >>>> } >>>> } >>>> >>>> private static boolean isChild(final Logger parentCandidate, final >>>> Logger childCandidate) { >>>> for (Category c =3D childCandidate; c !=3D null; c =3D >>>> c.getParent()) { >>>> if (c.equals(parentCandidate)) { >>>> return true; >>>> } >>>> } >>>> return false; >>>> } >>>> >>>> I suppose I could determine parent/child with a startWith on the logge= r >>>> name too. >>>> >>>> I there a better way to do this with the Core in v2 aside from >>>> iterating over all loggers in a context and doing a kind of isChild()?= Can >>>> additivity be used for this? >>>> >>>> I'd like to add such a utility method to Configurator. >>>> >>>> Gary >>>> >>>> -- >>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org >>>> >>>> Java Persistence with Hibernate, Second Edition >>>> >>>> JUnit in Action, Second Edition >>>> Spring Batch in Action >>>> Blog: http://garygregory.wordpress.com >>>> Home: http://garygregory.com/ >>>> Tweet! http://twitter.com/GaryGregory >>>> >>>> >>> >>> >>> -- >>> E-Mail: garydgregory@gmail.com | ggregory@apache.org >>> >>> Java Persistence with Hibernate, Second Edition >>> >>> JUnit in Action, Second Edition >>> Spring Batch in Action >>> Blog: http://garygregory.wordpress.com >>> Home: http://garygregory.com/ >>> Tweet! http://twitter.com/GaryGregory >>> >> >> >> >> -- >> E-Mail: garydgregory@gmail.com | ggregory@apache.org >> >> Java Persistence with Hibernate, Second Edition >> >> JUnit in Action, Second Edition >> Spring Batch in Action >> Blog: http://garygregory.wordpress.com >> Home: http://garygregory.com/ >> Tweet! http://twitter.com/GaryGregory >> > > > > -- > E-Mail: garydgregory@gmail.com | ggregory@apache.org > > Java Persistence with Hibernate, Second Edition > > JUnit in Action, Second Edition > Spring Batch in Action > Blog: http://garygregory.wordpress.com > Home: http://garygregory.com/ > Tweet! http://twitter.com/GaryGregory > > > --=20 E-Mail: garydgregory@gmail.com | ggregory@apache.org Java Persistence with Hibernate, Second Edition JUnit in Action, Second Edition Spring Batch in Action Blog: http://garygregory.wordpress.com Home: http://garygregory.com/ Tweet! http://twitter.com/GaryGregory --089e0158b78ef53291051de7e819 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Let's say I have=C2=A0

Logger com = =3D ERROR (or even just the root Logger at ERROR).

and I want Logger com.domain.foo and all its children set to DEBUG

If I=C2=A0ge= t the LoggerConfig that matches the parent logger and call setLevel on that= , I will end up with Logger com at DEBUG, won't I?

Gary

On Fri, Aug 21, 2015 at 9:53 PM, Ra= lph Goers <ralph.goers@dslextreme.com> wrote:
That = is definitely not how to implement it.

You should = get the LoggerConfig that matches your parent logger and call setLevel on t= hat. Then loop through all the loggerConfigs that start with the located Lo= ggerConfigs name and then call setLevel on them.=C2=A0 You typically aren= =E2=80=99t going to have many LoggerConfigs while you could have thousands = of Loggers, which all resolve to the same LoggerConfig.

Ralph

On Aug 21= , 2015, at 9:30 PM, Gary Gregory <garydgregory@gmail.com> wrote:

<= div dir=3D"ltr" style=3D"font-family:Helvetica;font-size:12px;font-style:no= rmal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-heig= ht:normal;text-align:start;text-indent:0px;text-transform:none;white-space:= normal;word-spacing:0px">
On Wed, Aug 19, 2015 at 7:59 PM, Gary Gregory=C2=A0<= garydgregory@gmail.com>=C2=A0wrote:
On Sat, Aug 15, 2015 at 3:56 PM, Gary Gregory=C2=A0<= span dir=3D"ltr"><garydgregory@gmail.com>=C2=A0wrote:
On Sat, Aug 15, 2015 at 3:07 PM, Ralph Goers=C2=A0<ralph.goers@dslextreme.com>=C2=A0= wrote:
Why do you want to set th= e level on the LoggerConfig and all its descendants?=C2=A0

Because I clearly did not e= ducate myself fully in this topic. ;-) Hence I am looking for a shortcut by= asking on the ML :-)
=C2=A0
Setting the level just on the LoggerConfig will achieve = the same thing, so long as none of its descendants has a LoggerConfig

That's cool, but... H= ow can I know if any descendant has a LoggerConfig? How can do this generic= ally?

Here i= s my proposal (including a test):=C2=A0https://issu= es.apache.org/jira/secure/attachment/12751400/log4j.diff

=
I am not crazy about the API name: setChildren(String loggerName= , Level level).

Thoughts?
<= /blockquote>

Anyone? Bueller? :-)
=C2=A0
=

Gary


Gary
=C2=A0

Sent from my iPad

On Aug 15, 2015, at 8:25 AM, Gary Gregory <garydgregory@gmail.com> w= rote:

Let'= s say I have a logger tree like:

R
R.P
R.P.C= 1
R.P.C1.L1
R.P.C2.L2
R.P.C= 2
R.P.C2.L1
R.P.C2.L2

= and I want to set R.P.C2 and all it's descendants to a given level.

In Log4j 1.2, I do:

=C2= =A0 =C2=A0=C2=A0public static void setChildren(final Logger pa= rentLogger, final Level newLevel) {
=C2=A0 =C2=A0 =C2=A0 =C2= =A0=C2=A0final Enumeration<Logger> enumeration =3D LogMa= nager.getCurrentLoggers();
=C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0while (enumeration.hasMoreElements()) {
=C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0final Logger logger =3D e= numeration.nextElement();
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0=C2=A0if (LoggerUtils.isChild(parentLogger, logger)) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0logger.setLevel(newLevel);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0=C2=A0}
=C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0}
=C2=A0 =C2=A0=C2=A0}
=
=C2=A0 =C2=A0=C2=A0private static boolean = isChild(final Logger parentCandidate, final Logger childCandidate) {
<= div>=C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0for (Category c =3D child= Candidate; c !=3D null; c =3D c.getParent()) {
=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0=C2=A0if (c.equals(parentCandidate)) {=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=C2= =A0return true;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0<= span>=C2=A0}
=C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0}
=C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0return false;
=C2=A0 =C2=A0=C2=A0}

I = suppose I could determine parent/child with a startWith on the logger name = too.

I there a better way to do this with the Core= in v2 aside from iterating over all loggers in a context and doing a kind = of isChild()? Can additivity be used for this?

I&#= 39;d like to add such a utility method to Configurator.

Gary

--=C2=A0
<= /div>



--=C2=A0

<= /div>


--
--089e0158b78ef53291051de7e819--