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 A04F9C73E for ; Mon, 26 May 2014 01:14:19 +0000 (UTC) Received: (qmail 34991 invoked by uid 500); 26 May 2014 01:14:19 -0000 Delivered-To: apmail-logging-log4j-dev-archive@logging.apache.org Received: (qmail 34940 invoked by uid 500); 26 May 2014 01:14:19 -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 34932 invoked by uid 99); 26 May 2014 01:14:19 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 26 May 2014 01:14:19 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of boards@gmail.com designates 209.85.219.45 as permitted sender) Received: from [209.85.219.45] (HELO mail-oa0-f45.google.com) (209.85.219.45) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 26 May 2014 01:14:13 +0000 Received: by mail-oa0-f45.google.com with SMTP id l6so7746678oag.32 for ; Sun, 25 May 2014 18:13:53 -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=DYx6aH6CE3V0dB+1ZS5YYnrSUwEC4hS88U22tKcdav8=; b=oqsahH8771LE7KFt/hC9Xial+/sDusl5UQRXypgcF0x4zqS9udkC0wcH90eNxxHhoO sdvnyqp3hisFCEYWZ8JhuRJ6CHkKBEGAjru27boIt9V6dgL4DOhIoxZ3l5sdrMdmfem4 YpGNkMV/8ukbOuJghCOp5U09jdLwCOnIJCHJ58q4Xu82MCdPZ7X3ogZ0Nt3CzYA52PbG ckrn/CUizR6DD+ci2VGpluAVkTemENuoCMhIrSymFcsen3kPVATPUzgcfs5/X4/lIpFM RGMKJiKqJklx588okYfA7+E6XvFyMIlK86ImmgurRfb660Ozere0E6UCSTkrUNoxmi5b Qv0Q== MIME-Version: 1.0 X-Received: by 10.60.179.80 with SMTP id de16mr5865186oec.69.1401066832946; Sun, 25 May 2014 18:13:52 -0700 (PDT) Received: by 10.76.72.68 with HTTP; Sun, 25 May 2014 18:13:52 -0700 (PDT) In-Reply-To: References: <47782C8A-894F-4C9D-85B3-C5FBDB12BB99@gmail.com> Date: Sun, 25 May 2014 20:13:52 -0500 Message-ID: Subject: Re: Have a question about how DefaultConfiguration and PatternLayout interact. From: Matt Sicker To: Log4J Developers List Content-Type: multipart/alternative; boundary=089e0118243ae26ecf04fa434ae1 X-Virus-Checked: Checked by ClamAV on apache.org --089e0118243ae26ecf04fa434ae1 Content-Type: text/plain; charset=UTF-8 DefaultConfiguration needs a Layout, and it uses PatternLayout for that. In PatternLayout, I don't want its Configuration to be null due to the field being used elsewhere by PatternLayout. Thus, to include a DefaultConfiguration in PatternLayout, and then a PatternLayout in DefaultConfiguration, I have to leak the this reference during construction to avoid creating an infinite loop of constructors. On 25 May 2014 20:10, Remko Popma wrote: > I had a look at the code and it may not be easy to make changes. Can we go > back a step and can you explain what you're trying to achieve? (What do you > want to change & why?) > > Sent from my iPhone > > On 2014/05/26, at 9:08, Matt Sicker wrote: > > Actually, that still leaves the problem of specifying a Configuration for > the DefaultConfigurationLayout. PatternLayout is final right now, and the > default pattern is "%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - > %msg%n". > > > On 25 May 2014 19:03, Matt Sicker wrote: > >> That sounds like a better idea. Let me see how well it works out in code. >> >> >> On 25 May 2014 18:52, Remko Popma wrote: >> >>> Perhaps DefaultConfigurationLayout would be a better name for such alayout, actually. >>> >>> >>> On Monday, May 26, 2014, Remko Popma wrote: >>> >>>> How about having a DefaultLayout for use *only* by >>>> DefaultConfiguration? The formatters used by this layout can be hard-coded: >>>> level, timestamp, message. >>>> Thoughts? >>>> >>>> Sent from my iPhone >>>> >>>> On 2014/05/26, at 8:38, Matt Sicker wrote: >>>> >>>> So DefaultConfiguration creates a PatternLayout, but PatternLayout >>>> takes a Configuration. I thought it would help prevent NPEs using a >>>> DefaultConfiguration as the default, but then upon trying that, I found >>>> myself in an infinite recursion of constructors! >>>> >>>> In order to provide a default, we have a few options: >>>> >>>> 1. Use NullConfiguration by default. Problem is, this basically means >>>> "ignore all logging calls". >>>> >>>> 2. Lazily create the DefaultConfiguration if configuration is null at >>>> build() time. >>>> >>>> 3. Leak "this" from the DefaultConfiguration constructor into the >>>> PatternLayout used for the default ConsoleAppender which is used as the >>>> default appender on the root logger. It's not pure, but sometimes you do >>>> need to leak an object before it's been fully constructed. >>>> >>>> 4. Add another attribute to disable setting a Configuration. I don't >>>> like this option as it introduces extra complexity and doesn't solve the >>>> problem of having a null config (and not a NullConfiguration). >>>> >>>> Right now, I'm leaning toward 2 and 3 combined. >>>> >>>> -- >>>> Matt Sicker >>>> >>>> >> >> >> -- >> Matt Sicker >> > > > > -- > Matt Sicker > > -- Matt Sicker --089e0118243ae26ecf04fa434ae1 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
DefaultConfiguration needs a Layout, and it uses PatternLa= yout for that. In PatternLayout, I don't want its Configuration to be n= ull due to the field being used elsewhere by PatternLayout. Thus, to includ= e a DefaultConfiguration in PatternLayout, and then a PatternLayout in Defa= ultConfiguration, I have to leak the this reference during construction to = avoid creating an infinite loop of constructors.


On 25 May 201= 4 20:10, Remko Popma <remko.popma@gmail.com> wrote:
<= blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px= #ccc solid;padding-left:1ex">
I had a look at the code and it may not be easy to m= ake changes. Can we go back a step and can you explain what you're tryi= ng to achieve? (What do you want to change & why?)

Sent from my = iPhone

On 2014/05/26, at 9:08, Matt Sicker <boards@gmail.com>= wrote:

Actual= ly, that still leaves the problem of specifying a Configuration for the Def= aultConfigurationLayout. PatternLayout is final right now, and the default = pattern is=C2=A0"%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %ms= g%n".


On 25 May 201= 4 19:03, Matt Sicker <boards@gmail.com> wrote:
That sounds like a better idea. Let me see how well it wor= ks out in code.


On 25 May 2014 18:52, Remko Popma <<= a href=3D"mailto:remko.popma@gmail.com" target=3D"_blank">remko.popma@gmail= .com> wrote:
Perhaps DefaultConfigurationLayout would be = a better name for such a layout, actually.=C2=A0


On Monday, May 26, 2014, Remko Popma <remko.popma@gmail.com> wrote:<= br>
How about having a De= faultLayout for use *only* by DefaultConfiguration? The formatters used by = this layout can be hard-coded: level, timestamp, message.=C2=A0
Thoughts?

Sent from my iPhone

On 2014/05/26, at 8= :38, Matt Sicker <boards@gmail.com> wrote:

So DefaultConfigu= ration creates a PatternLayout, but PatternLayout takes a Configuration. I = thought it would help prevent NPEs using a DefaultConfiguration as the defa= ult, but then upon trying that, I found myself in an infinite recursion of = constructors!

In order to provide a default, we have a few options:
<= div>
1. Use NullConfiguration by default. Problem is, this ba= sically means "ignore all logging calls".

2. Lazily create the DefaultConfiguration if configuration is null at = build() time.

3. Leak "this" from the De= faultConfiguration constructor into the PatternLayout used for the default = ConsoleAppender which is used as the default appender on the root logger. I= t's not pure, but sometimes you do need to leak an object before it'= ;s been fully constructed.

4. Add another attribute to disable setting a Configura= tion. I don't like this option as it introduces extra complexity and do= esn't solve the problem of having a null config (and not a NullConfigur= ation).

Right now, I'm leaning toward 2 and 3 combined.

--
Matt Sicker <boards@gmail.com= >



<= /div>--
Matt Sicker <boards@gmail.com>



--
Matt Sicker = <boards@gmail.com<= /a>>



--
Matt Sicker <
boards@gmail.com> --089e0118243ae26ecf04fa434ae1--