[slf4j-user] Serializable log adapters

Sebastien Pennec sebastien at qos.ch
Mon Mar 12 14:42:18 CET 2007


Hello Jeremy,

When you serialize an object that contains a logger, it will be re-built at a given 
time. At that moment, maybe on another machine, the logger context may be very different.

And when you will try to log after re-building the object, the logger will not know 
which context it is supposed to be attached to.

In your case, I think that loggers should be set transient. They are not serialized, 
and not rebuilt once another machine receives the object. However, it does not mean 
that it is not possible to log anymore! Setting a logger transient only forces you to 
retrieve a new logger when using a re-built object. This will retrieve a logger that 
will be attached to the available context, and allow you to log properly.

Could that solution suit your needs?

Sébastien


Jeremy Booth wrote:
> Hi
> 
> I'm currently using JCL, but I'm about to include in my own project,
> another library that uses slf4j. It seems to make sense to only use 1
> façade. Unfortunately, the slf4j loggers and adapters do not implement
> serializable, which causes issues with my back end code that stores my
> objects to a database using serialisation (not my code, so can't be
> changed).
> 
> Is there a reason why the adapters don't implement serializable other
> than a lack of demand? Would it be possible to make them serializable so
> I can switch?, looking at the javadocs I assume it would be the logger
> adapter implementations, org.slf4j.spi.LocationAwareLogger and
> org.slf4j.Logger that would need the change.
> 
> I have the source and can do the change, I'm just checking on the
> technical issues that I may not understand as I am new to the API.
> 
> Thanks
> 
> Jeremy
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> user mailing list
> user at slf4j.org
> http://www.slf4j.org/mailman/listinfo/user

-- 
Sébastien Pennec
sebastien at qos.ch

Logback: The reliable, generic, fast and flexible logging framework for Java.
http://logback.qos.ch/



More information about the slf4j-user mailing list