logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Morten Hattesen" <morten.hatte...@gmail.com>
Subject Re: Suggestion - 1.3 API, Logger method signatures
Date Tue, 12 Dec 2006 08:52:16 GMT
I believe the goal for Log4J 1.3 was to maintain JDK 1.2
compatibility, so using varargs is a no-go, although it would be
convenient for JDK 5.0 (or 1.5 ;-)

Morten Hattesen

On 12/12/06, Adrian Sandor <aditsu@yahoo.com> wrote:
> I don't use java <1.5 at all, so I would prefer: public void debug(Object messagePattern,
Object... args);
>
> I suppose it has the same overhead though (because of automatic boxing and array creation),
just much sweeter to write.
>
> As for throwables, it has to be like: public void trace(Object messagePattern, Throwable
t, Object... args);
>
> About formatting style, maybe the getLogger method should also accept an extra argument
for choosing what kind of formatting to use (printf / MessageFormat / ...) or it could even
use some kind of formatter interface (that users can implement the way they like, with some
default implementations provided).
>
> Regards,
> Adrian
>
> ----- Original Message ----
> From: Morten Hattesen <morten.hattesen@gmail.com>
> To: log4j-user@logging.apache.org
> Sent: Monday, December 11, 2006 10:22:28 PM
> Subject: Suggestion - 1.3 API, Logger method signatures
>
> Hi,
>
> The Log4J 1.3 API changes to the org.apache.log4j.Logger API was
> changed to allow the use of use message patterns
> http://logging.apache.org/log4j/docs/api-1.3/org/apache/log4j/Logger.html
>
> This was obviously done do avoid excessive string concatenation by the
> compiler when calling a logging method, as well as to make the code
> more legible.
>
> Example (log4j 1.2 api):
>
>     logger.debug("Fetching data for " + user.name + " from database");
>
> ... may be expressed like so in log4j 1.3:
>
>     logger.debug("Fetching data for {0} from database", user.name);
>
> As a side effect it is no longer as essential to wrap calls to logging
> methods in a conditional ...
>
>     if (logger.isDebugEnabled) {
>         logger.debug(...);
>     }
>
> ... since the string concatenation overhead is now not incurred unless
> the logging actually takes place.
>
> However, what surprises me, is that the API only supports 1 and 2
> argument messages, and that message pattern is not supported at all
> when passing a throwable.
>
> I can see a point in allowing a single argument convenience method
> signature, e.g.:
>
>     public void debug(Object messagePattern, Object arg);
>
> But to support multiple (2 or more) arguments (using JRE 1.2), an
> Object array should be used, e.g:
>
>     public void debug(Object messagePattern, Object[] args);
>
> In other words, I suggest that all the two-argument methods of
> org.apache.log4j.Logger (and its deprecated super classes) should be
> removed, e.g:
>
>     public void xxxx(String messagePattern, Object arg1, Object arg2);
>
> ... and replaced by ...
>
>     public void xxxx(String messagePattern, Object[] args);
>
>
> Also, I feel that in order to keep the 1.3 API "clean" the logging
> methods that take a throwable argument should be overloaded with
> message pattern arguments, too, e.g.
>     public void trace(Object messagePattern, Object arg, Throwable t);
>     public void trace(Object messagePattern, Object[] args, Throwable t);
>
>
> Can I please get some views on this subject from other Log4J users,
> before submitting it formally to the developers' list.
>
> Regards,
>
> Morten Hattesen
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>
>
>
>
>
>
>
>
> ____________________________________________________________________________________
> Do you Yahoo!?
> Everyone is raving about the all-new Yahoo! Mail beta.
> http://new.mail.yahoo.com
>

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


Mime
View raw message