You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by op...@mail.telepac.pt on 2007/01/22 17:13:02 UTC

Log4j and Serializable classes

Hi,

Log4j works in objects that implements Serializable?

If so, how this is possible? If a client receives an object from the server that
implements Serializable, how the client knows how to interpret log4j
instructions?

Sincerely,
Pedro

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Log4j and Serializable classes

Posted by James Stauffer <st...@gmail.com>.
I don't quite understand.  Do you want to serialize log4j classes?
Anytime that you serialize an object both the client and server need
all classes that the object uses.  If the object has a log4j Logger
than both the client and server should have log4j.jar in the
classpath.

On 1/22/07, op132650c@mail.telepac.pt <op...@mail.telepac.pt> wrote:
> Hi,
>
> Log4j works in objects that implements Serializable?
>
> If so, how this is possible? If a client receives an object from the server that
> implements Serializable, how the client knows how to interpret log4j
> instructions?
>
> Sincerely,
> Pedro
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>


-- 
James Stauffer        http://www.geocities.com/stauffer_james/
Are you good? Take the test at http://www.livingwaters.com/good/

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Log4j and Serializable classes

Posted by Curt Arnold <ca...@apache.org>.
On Jan 22, 2007, at 10:13 AM, op132650c@mail.telepac.pt wrote:

> Hi,
>
> Log4j works in objects that implements Serializable?
>
> If so, how this is possible? If a client receives an object from  
> the server that
> implements Serializable, how the client knows how to interpret log4j
> instructions?
>
> Sincerely,
> Pedro
>

I am not sure I understand your question.

The most common pattern of using log4j is for a class to have a  
static member representing to logger, something like:

class MyClass implements Serializable {
     private static final Logger logger = Logger.getLogger 
(MyClass.class);
     ...
}

With this pattern, the logger is not an instance variable of the  
class and is not serialized with the class.  On the receiving end,  
the value of MyClass.logger will be initialized when MyClass is  
loaded which may be when the first instance of the class is  
deserialized.  The log4j.jar will need to be on the classpath for the  
receiving application.  If log4j has not been configured before  
deserializing, the receiving application will be configured following  
the default configuration pattern (that is looking for  
log4j.properties and log4j.xml).  It would be totally possible for  
the logger on the sending end to have a different threshold than on  
the receiving end.



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Log4j and Serializable classes

Posted by Jacob Kjome <ho...@visi.com>.
At 10:13 AM 1/22/2007, you wrote:
 >Hi,
 >
 >Log4j works in objects that implements Serializable?
 >
 >If so, how this is possible? If a client receives an object from the
 >server that
 >implements Serializable, how the client knows how to interpret log4j
 >instructions?
 >

Log4j Loggers are not Serializable.  You must make them either static 
variables or make them transient.  If it's static, then you don't 
need to do much else.  If it's transient, then you'll need to make 
sure you re-initialize the instance in readObject(), otherwise it 
will be null (or default value if it's a primitive) in the 
deserialized object.  I suggest you read up on serializtion....

http://www.churchillobjects.com/c/11009.html


Jake

 >Sincerely,
 >Pedro
 >
 >---------------------------------------------------------------------
 >To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
 >For additional commands, e-mail: log4j-user-help@logging.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org