[slf4j-dev] Benefits of Message objects?

Joern Huxhorn jhuxhorn at googlemail.com
Sat Sep 10 20:28:59 CEST 2011


On 10.09.2011, at 15:53, Ceki Gulcu wrote:

> On 07.09.2011 21:47, Joern Huxhorn wrote:
>> Ok, huge post is incoming... ;)
>> 
>> To properly explain the reason for Message I should start with my redefinition of the Logger interfaces.
>> 
>> ## core.BasicLogger
>> 
>> I created a BasicLogger interface ( https://github.com/huxi/slf4j/blob/slf4j-redesign/slf4j-n-api/src/main/java/org/slf4j/core/BasicLogger.java ) that merely defines the following methods:
>> 	boolean isEnabled(T level);
>> 	void log(T level, Message message);
>> 	void log(T level, Message message, Throwable throwable);
>> 
>> As you can see, Message is already used in this interface. The idea is that several different
>> Logger systems can be created extending it, e.g. Classic, Access or your Audit logger.
> 
> Access does not have use for Level nor Throwable. Audit has no use for
> Level.  Logback-audit has quite a different API than
> logback-classic. For example, exceptions thrown during audit logging
> are rethrown to the user as AuditExceptions. It is not obvious that
> merging developer (classic) logging, access logging and audit logging
> into a single API makes sense.

The idea here was to use https://github.com/huxi/slf4j/blob/slf4j-redesign/slf4j-n-api/src/main/java/org/slf4j/a/HttpStatusType.java as the "Level" for AccessLogging. I assumed that such a general category exists for most cases. I'm not sure about Audit logging but I assume that it also contains events of different importance/kind.
(I don't think that this package should end up in the final version of this jar. It is only there as an example.)

In case of access logging it would make sense to just log 4xx and 5xx, only 5xx or to log those events into different files.
This general support for categories is implemented to support guarding with the isEnabled method. Level is probably a bad name for the variable in that signature. It is there for historic reasons. ;)

Cheers,
Joern.


More information about the slf4j-dev mailing list