logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ceki Gülcü <c...@qos.ch>
Subject RE: cvs commit: logging-log4j/tests/src/java/org/apache/log4j/helpers/mcomposer MessageComposerTest.java
Date Fri, 29 Oct 2004 19:37:01 GMT
He he. I was attempting to think ahead. The caching of the parsed
result would necessitates at least 2 other classes. The cache class
itself plus a data structure to hold the parsed results. But since it
is not really sure that caching the parsed results would bring a real
performance boost, you are probably right... :-)

(Parsing is only performed if the logger knows the message needs to be
logged. In that case, parsing time is likely to be significantly
faster than formatting the results and outputting them on a file or
some other device. In other words, no need to optimize code that takes
1% of what it takes to execute a logging call. I do not have exact
numbers so its all guessware at this point.)

At 09:21 PM 10/29/2004, Gary Gregory wrote:
>Aside from whether these are good reasons or not, I do think that creating 
>a new namespace - "mcomposer" - is over the top, not to mention cryptic.
>
>Letting it live in ".helpers" would be fine, or if you really want a new 
>namespace, in ".text" or in ".helpers.text".
>
>2c,
>Gary
>
> > -----Original Message-----
> > From: Ceki Gülcü [mailto:ceki@qos.ch]
> > Sent: Friday, October 29, 2004 05:10
> > To: Log4J Developers List
> > Subject: RE: cvs commit: logging-
> > log4j/tests/src/java/org/apache/log4j/helpers/mcomposer
> > MessageComposerTest.java
> >
> >
> > Hi Paul,
> >
> > There are several reasons.
> >
> > 1) With MessageComposer one can write:
> >
> >    logger.debug("My name is {}.", name);
> >    logger.debug("My name is {}. I am {} years old", name, age);
> >
> > instead of
> >
> >    logger.debug("My name is {0}.", name);
> >    logger.debug("My name is {0}. I am {1} years old", name, age);
> >
> > with java.text.MessageFormat.
> >
> > I think the omission of the numbered parameters makes writing debug
> > statements quicker and easier for the user. You have to try it 4 or 5
> > times to notice the difference but it becomes quite noticeable after a
> > short while.
> >
> > 2) Since MessageComposer has a smaller scope, it should perform its
> > parsing duties significantly faster then java.text.MessageFormat.
> > Moreover, since we have access to the internals of MessageComposer, we
> > can modify it so that it caches its results. Thus, the next time a
> > given message needs to be output, we can use the parsed structure and
> > economize the work involved in parsing the message.
> >
> > 3) MessageComposer has been already implemented and tested.
> >
> > Do you think these are good reasons?
> >
> > At 12:15 AM 10/29/2004, you wrote:
> > >Ceki, is there any reason to have MessageComposer when there is the
> > >java.text.MessageFormat class available from JDK1.2 that appears to do
> > >exactly the same thing?  (There could well be a good reason, I just can't
> > >see it as yet).
> > >
> > >Just curious.
> > >
> > >cheers,
> > >
> > >Paul Smith
> > >
> > > > -----Original Message-----
> > > > From: ceki@apache.org [mailto:ceki@apache.org]
> > > > Sent: Thursday, October 28, 2004 11:13 PM
> > > > To: logging-log4j-cvs@apache.org
> > > > Subject: cvs commit:
> > > > logging-log4j/tests/src/java/org/apache/log4j/helpers/mcomposer
> > > > MessageComposerTest.java
> > > >
> > > >
> > > > ceki        2004/10/28 06:12:35
> > > >
> > > >   Added:       tests/src/java/org/apache/log4j/helpers/mcomposer
> > > >                         MessageComposerTest.java
> > > >   Log:
> > > >   Unit tests for MessageComposer
> > > >
> > > >   Revision  Changes    Path
> > > >   1.1
> > > > logging-log4j/tests/src/java/org/apache/log4j/helpers/mcomposer/Me
> > > > ssageComposerTest.java
> > > >
> > > >   Index: MessageComposerTest.java
> > > >   ===================================================================
> > > >   /*
> > > >    * Copyright 1999,2004 The Apache Software Foundation.
> > > >    *
> > > >    * Licensed under the Apache License, Version 2.0 (the "License");
> > > >    * you may not use this file except in compliance with the License.
> > > >    * You may obtain a copy of the License at
> > > >    *
> > > >    *      http://www.apache.org/licenses/LICENSE-2.0
> > > >    *
> > > >    * Unless required by applicable law or agreed to in writing,
> > software
> > > >    * distributed under the License is distributed on an "AS IS" BASIS,
> > > >    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
> > > > or implied.
> > > >    * See the License for the specific language governing permissions
> > and
> > > >    * limitations under the License.
> > > >    */
> > > >
> > > >   package org.apache.log4j.helpers.mcomposer;
> > > >
> > > >   import org.apache.log4j.helpers.mcompose.MessageComposer;
> > > >
> > > >   import junit.framework.TestCase;
> > > >
> > > >
> > > >   /**
> > > >    * @author Ceki Gulcu
> > > >    *
> > > >    */
> > > >   public class MessageComposerTest extends TestCase {
> > > >
> > > >     public void test1Param() {
> > > >       String result;
> > > >       Integer i3 = new Integer(3);
> > > >
> > > >       result = MessageComposer.compose("Value is {}.", i3);
> > > >       assertEquals("Value is 3.", result);
> > > >
> > > >       result = MessageComposer.compose("Value is {", i3);
> > > >       assertEquals("Value is {", result);
> > > >
> > > >       result = MessageComposer.compose("Value is {}.", null);
> > > >       assertEquals("Value is null.", result);
> > > >
> > > >       result = MessageComposer.compose("{} is larger than 2.", i3);
> > > >       assertEquals("3 is larger than 2.", result);
> > > >
> > > >       result = MessageComposer.compose("No subst", i3);
> > > >       assertEquals("No subst", result);
> > > >
> > > >       result = MessageComposer.compose("Incorrect {subst", i3);
> > > >       assertEquals("Incorrect {subst", result);
> > > >
> > > >       result = MessageComposer.compose("Escaped \\{} subst", i3);
> > > >       assertEquals("Escaped \\{} subst", result);
> > > >
> > > >       result = MessageComposer.compose("\\{Escaped", i3);
> > > >       assertEquals("\\{Escaped", result);
> > > >
> > > >       result = MessageComposer.compose("\\{}Escaped", i3);
> > > >       assertEquals("\\{}Escaped", result);
> > > >     }
> > > >
> > > >     public void test2Param() {
> > > >       String result;
> > > >       Integer i1 = new Integer(1);
> > > >       Integer i2 = new Integer(2);
> > > >
> > > >       result = MessageComposer.compose("Value {} is larger than
> > > > {}.", i1, i2);
> > > >       assertEquals("Value 1 is larger than 2.", result);
> > > >
> > > >       result = MessageComposer.compose("Value {} is larger than
> > > > {}", i1, i2);
> > > >       assertEquals("Value 1 is larger than 2", result);
> > > >
> > > >       result = MessageComposer.compose("{}{}", i1, i2);
> > > >       assertEquals("12", result);
> > > >       result = MessageComposer.compose("Val1={}, Val2={", i1, i2);
> > > >       assertEquals("Val1=1, Val2={", result);
> > > >     }
> > > >   }
> > > >
> > > >
> > > >
> > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
> > > > For additional commands, e-mail: log4j-dev-help@logging.apache.org
> > > >
> > > >
> > > >
> > >
> > >
> > >---------------------------------------------------------------------
> > >To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
> > >For additional commands, e-mail: log4j-dev-help@logging.apache.org
> >
> > --
> > Ceki Gülcü
> >
> >       For log4j documentation consider "The complete log4j manual"
> >       http://www.qos.ch/shop/products/eclm/
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
> > For additional commands, e-mail: log4j-dev-help@logging.apache.org
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
>For additional commands, e-mail: log4j-dev-help@logging.apache.org

-- 
Ceki Gülcü

      For log4j documentation consider "The complete log4j manual"
      http://www.qos.ch/shop/products/eclm/  



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Mime
View raw message