[slf4j-user] Why is Logger not serializable

ceki ceki at qos.ch
Thu Feb 9 15:16:23 CET 2012


On 01.02.2012 17:01, cowwoc wrote:
> Florian,
>
> According to Effective Java the Serializable mechanism (like other
> "marker interfaces") has problems and so to avoid "infecting" all
> implementations (requiring them to actually implement Serializable)
> you're supposed to just mark the implementation classes.

I was not aware of the discussion in " Effective Java". I'll look it
up. Thank you.

> The code-analysis tool is right in the sense you could end up using a
> Logger implementation which is *not* serializable (I believe Logback
> is). You can either depend on Logback directly or ask the code analysis
> tool to suppress the warning for this field.

Depending directly on logback would not be a good idea. Configuring
the code analysis tool to suppress serialization warnings for all
logger fields *one by one* is possible but may entail a lot of
work. Ideally, the code analysis tool should allow ignoring
serialization of logger fields.

> Gili
>
> On 01/02/2012 9:32 AM, florian.huonder at itartis.ch wrote:
>> Hi all,
>>
>> In the FAQ of SLF4J it says "As of SLF4J version 1.5.3, logger
>> instances survive serialization". For me this means that all SLF4J
>> loggers are serializable. But only the Logger implementations are
>> Serializable "not the interface".

That is correct. While the Logger interface is not marked as
Serializable, all Logger implementations shipping with SLF4J
(slf4j-jdk14, slf4j-log4j12, slf4j-simple,...) as well the
implementation shipping in logback-classic are Serializable.

>> Due to this my code analysis criticizes "Non-transient
>> non-serializable instance field in serializable class" for the logger.
>> So my question is why does the logger interface not extend
>> Serializable? From the FAQ i understand that it is part of the
>> contract of a Logger implementation that it is serializable.

Good question. As Gili mentioned, the idea was to allow the freedom for 
other Logger implementations to be non-serializable. Admittedly, this 
contradicts the FAQ which states that "As of SLF4J version 1.5.3, logger 
instances survive serialization."

To make a long story short, I dare not touch/modify the signature of 
org.slf4j.Logger for reasons of backward compatibility.

>> Best regards,
>> Florian

-- 
Ceki
http://twitter.com/#!/ceki


More information about the slf4j-user mailing list