commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stumm, Roman" <RSt...@CONET.DE>
Subject [Logging] Making Logs serializable
Date Fri, 08 Aug 2003 15:57:54 GMT

> Hello,
> 
> I want to propose a minor change on the implementation classes of the
> interface org.apache.commons.logging.Log.
> 
> We are using your API inside our classes, that might themselves be used
> inside an EJB container. 
> Sometimes it is useful to have a Log instance in an instance variable
> (e.g. for some utility classes, that are used in various contexts). This
> has the advantage, that each instance can use the Log that it gets by its
> clients. The problem is then, that when the EJB container passivates such
> utilities (e.g. when they are serialized) the implementation of Log are
> not serializable. This results in our utility classes being not
> serializable anymore, when they hold a reference to Log. 
> (Making the Log instance transient does not solve the problem, because it
> will be null after deserialization.)
> 
> With the minor change I propose, some implementation classes (we are
> currently logging with log4J) can be serializable and recreate a reference
> to their CategoryLogger during deserialization.
> 
> I would like to know, if this change could get into one of your next
> releases.
> 
> With best regards,
> Roman Stumm
> CONET Consulting, Hennef (Germany)
> 
> So here are the changes that I propose to make Log4JLogger serializable:
> (Log4JLogger implements Serializable and has 2 private methods)
> 
> package org.apache.commons.logging.impl;
> 
> // ...
> 
> public final class Log4JLogger implements Log, java.io.Serializable {
> 
>   // ... here the implementation that you already have in
> commons-logging-1.0.3-src
> 
>   private void writeObject(java.io.ObjectOutputStream out)
>           throws java.io.IOException {        
>     out.writeObject(logger.getName());
>   }
> 
>   private void readObject(java.io.ObjectInputStream in)
>           throws java.io.IOException, ClassNotFoundException {
>     logger = Logger.getLogger((String) in.readObject());
>   }
> }
> 
> (a similar solution should work for Jdk14Logger)

Mime
View raw message