[slf4j-dev] [Bug 31] Varargs for Logger methods

bugzilla-daemon at pixie.qos.ch bugzilla-daemon at pixie.qos.ch
Sun Feb 14 12:38:56 CET 2010


http://bugzilla.slf4j.org/show_bug.cgi?id=31





--- Comment #78 from Joern Huxhorn <joern at huxhorn.de>  2010-02-14 12:38:55 ---
(In reply to comment #77)
> I think that your approach with having the varargs logger in a completely
> separate package is the right solution.

Thanks.

> I also think that the methods in the interface should be as simple as possible
> while still conveying meaning.  In other words the mandatory formating string
> must be explicitly defined, but the exception cannot as it breaks the varargs
> convention (to my understanding). 
> 
> I'd vote for a new Logger interface in a separate package (shipped separately
> from slf4j-api too) providing only
> 
>   log.error(String, Object...)
>   log.warn(String, Object...)
>   log.info(String, Object...)
>   log.debug(String, Object...)

My proposal defines some more methods.
logger.log(Level, String, Object...)
logger.log(Level, Marker, String, Object...)
logger.log(Level, Message)
logger.log(Level, Marker, Message)
logger.log(Level, Message, Throwable)
logger.log(Level, Marker, Message, Throwable)

The same explicitly for each level, with the Level argument omitted, obviously.

That way it's possible to create and use arbitrary other Message
implementations, beside the default implementation that is used when (String,
Object...) is called. The default formats exactly like the current SLF4J
message format.

> which then invokes the appropriate methods in the current slf4j API (unless
> Logback implements these too natively).  Simply looking at the last element to
> see if it is a Throwable or not, should be enough?

I think so, yes.
It adheres to the POLA (
http://en.wikipedia.org/wiki/Principle_of_least_astonishment )

> My only concern is that it breaks the "log-where-I-came-from" mechanisms.  This
> is less important to me.
> 

This shouldn't be a problem due to the LocationAwareLogger.


-- 
Configure bugmail: http://bugzilla.slf4j.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.


More information about the slf4j-dev mailing list