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 0CF6DE368 for ; Fri, 7 Dec 2012 22:21:57 +0000 (UTC) Received: (qmail 52864 invoked by uid 500); 7 Dec 2012 22:21:56 -0000 Delivered-To: apmail-logging-log4j-dev-archive@logging.apache.org Received: (qmail 52815 invoked by uid 500); 7 Dec 2012 22:21:56 -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 52807 invoked by uid 99); 7 Dec 2012 22:21:56 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 07 Dec 2012 22:21:56 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS,URIBL_DBL_REDIR X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of garydgregory@gmail.com designates 209.85.213.195 as permitted sender) Received: from [209.85.213.195] (HELO mail-ye0-f195.google.com) (209.85.213.195) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 07 Dec 2012 22:21:50 +0000 Received: by mail-ye0-f195.google.com with SMTP id r1so84029yen.10 for ; Fri, 07 Dec 2012 14:21:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=Fe21Gsh4z3gukXjocMTE0iTgDqV78e7aYTg0Vo3FYqQ=; b=snIssdY5NpIfQwIHRXKQeVy333K8YUrLce6o47drZ9GGUSPzNqNJFXsqn8Um4qU8uO efchWD0OYwwH5lj+8iqY+qxKsDdnB78rHnUiRq0VTU+DoVYgPj1ketc39xRhUcdDdiK8 zkUvPO3SZm3GLGtFv1Nz5yqnHK1f/HRSaour88/menUUSVuuA3SOMkMyF0JNFnvrgcTE SpQhry1aizQSzDcic1W6YjCIOZ2E1hR6srZHTagx0JyvlWOqcxZNcuDxHVHUwloEKleb HanibDs1O7rfueEX/gvJwMdvumQjucRLuGDbo6xJqQX4Lf9QaUdZ2koJ0BGLTQ/Se1bs tKwg== MIME-Version: 1.0 Received: by 10.100.250.2 with SMTP id x2mr2888542anh.14.1354918889687; Fri, 07 Dec 2012 14:21:29 -0800 (PST) Received: by 10.147.16.22 with HTTP; Fri, 7 Dec 2012 14:21:29 -0800 (PST) Date: Fri, 7 Dec 2012 17:21:29 -0500 Message-ID: Subject: [LOG4J2-133] part 2: LogManager API From: Gary Gregory To: Log4J Developers List Content-Type: multipart/alternative; boundary=001636af02731e8b3004d04aa35a X-Virus-Checked: Checked by ClamAV on apache.org --001636af02731e8b3004d04aa35a Content-Type: text/plain; charset=UTF-8 I've attached to LOG4J2-133 a part 2 diff file. This gives us a way to pass a MessageFactory to new getLogger(String|Class|Object, MessageFactory) APIs. For example: TestLogger testLogger = (TestLogger) LogManager.getLogger(TestStringFormatterMessageFactory.class, new StringFormatterMessageFactory()); assertNotNull(testLogger); testLogger.debug("%,d", Integer.MAX_VALUE); assertEquals(1, testLogger.getEntries().size()); assertEquals(String.format(" DEBUG %,d", Integer.MAX_VALUE), testLogger.getEntries().get(0)); When you call getLogger(String|Class|Object), you get a Logger back, if there is not one, it is created. Now we have new APIs with a MessageFactory parameter. This parameter is only used when creating the logger, which means it is only used the first time the API is called. If you subsequently call getLogger for the same logger, the MessageFactory is ignored. When the Logger is created, the MessageFactory is saved in a final ivar field. I did not document this in the API yet but I plan on doing so. Does anyone see a better way than documentation to deal with this? Should a warning be logged if you call getLogger with a message factory that is different than the one already set? Thank you, Gary -- E-Mail: garydgregory@gmail.com | ggregory@apache.org JUnit in Action, 2nd Ed: http://bit.ly/ECvg0 Spring Batch in Action: http://bit.ly/bqpbCK Blog: http://garygregory.wordpress.com Home: http://garygregory.com/ Tweet! http://twitter.com/GaryGregory --001636af02731e8b3004d04aa35a Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable I've attached to LOG4J2-133 a part 2 diff file.

This gives us a = way to pass a MessageFactory to new getLogger(String|Class|Object, MessageF= actory) APIs.

For example:

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0 TestLogger testLogger =3D (TestLogger) LogManager.getLogger(TestS= tringFormatterMessageFactory.class,
=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 new StringFormatterMessageFactory());
=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 assertNotNull(testLogger);
=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 testLogger.debug("%,d", Integer.MAX_VALU= E);
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 assertEquals(1, testLogge= r.getEntries().size());
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 asser= tEquals(String.format(" DEBUG %,d", Integer.MAX_VALUE), testLogge= r.getEntries().get(0));

When you call getLogger(String|Class|Object), you get a Logger back, if= there is not one, it is created.

Now we have new APIs with a Messag= eFactory parameter. This parameter is only used when creating the logger, w= hich means it is only used the first time the API is called.

If you subsequently call getLogger for the same logger, the MessageFact= ory is ignored.

When the Logger is created, the MessageFactory is sa= ved in a final ivar field.

I did not document this in the API yet bu= t I plan on doing so.

Does anyone see a better way than documentation to deal with this?
<= br>Should a warning be logged if you call getLogger with a message factory = that is different than the one already set?

Thank you,
Gary

--
E-Mail: garydgregory@gmail.com | ggregory@apache.org
JUnit in Action, 2nd Ed: http://bit.ly/ECvg0
Spring Batch in Action: = http://bit.ly/bqpbCK
Blog: http://garygregory.wordpress.com
Home: http://garygreg= ory.com/
Tweet! http://twitter.com/GaryGregory
--001636af02731e8b3004d04aa35a--