At 11:45 PM 11/2/2004, Paul Smith wrote:

Actually, I was thinking along the lines of:

   logger.debug("My name is {1}. I am {0} years old", new Object[]{new
Integer(30}, "Paul"});

Which is more cryptic, no arguments there, but more flexible:

* It can handle practically unlimited # of args

Good point. However, keep in mind:

1) the 'new Object[]' part creates a superfluous object, i.e the
object array itself. Avoiding the creation of these superfluous
objects was the reason for this whole exercise. It turns out that the
cost of 'new Object[]' is about 8 times cheaper than the cost of
multiple string concatenation.  So, while the 'new Object[]'
constitutes progress over naive string concatenation, it is not as good as
the "if(logger.debugEnabled()){...}" form, as explained in 2).

2) If more 3 or more arguments need to be handled, one can always write

if(logger.debugEnabled()) {
  logger.info("We can put "+here+" as many "+args+" as "+name+" wants.");
}

I consider the if(logger.debugEnabled()){...} form as readable (or as
cryptic) as the the 'new Object[]' form. It has the distinct advantage
of completely avoiding superfluous object creation.

* Order of args can be different from the order they are displayed.

I don't see any real added value in allowing different argument ordering between those in the message pattern and those in the argument array. IMHO, it just creates one more way for the user to make a mistake.

It would surely be easier to use, I cannot argue that, but, how many
arguments will we support? 2?  5? 10?  It seems limiting to me, despite the
ease of use.

Any comments on that?

As mentioned previously, you can always write if(logger.debugEnabled()){...} to handle 3 or more arguments.

In conclusion, I think that between the isXXXEnabled methods and the
printing methods taking one or two arguments plus a message pattern,
there is no need for the object array variant. Given the above, would
you agree?


Paul Smith

-- Ceki G�lc�

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




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to