tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Spiegs <spi...@spiegs.com>
Subject Re: Serializable Logging implementation
Date Fri, 17 Sep 2004 00:49:17 GMT
What is the best approach for someone starting a new app? Is having all 
of your model objects contain a transient static log instance, implement 
Serializable, and implement HttpSessionActivationListener to 
reinstantiate the log instance the best approach? What other approaches 
would you recommend if you were to start with a clean slate?

If you were to put the above code into a superclass, doesn't that go 
against the previously discussed advice of having the log instance 
belong to each class?

Thanks,
Eric

-------- Original Message ------
Subject:
Re: Serializable Logging implementation
From:
Tim Funk <funkman@joedog.org>
Date:
Wed, 15 Sep 2004 09:20:06 -0400

To:
Tomcat Users List <tomcat-user@jakarta.apache.org>


Your NPE comes from the transient value not being restored from 
de-serialization.

Your best chance at this point without a lot of code changes is to
1) Make your log variable transient
2) Make your base class implement HttpSessionActivationListener.
3) Make your implementation of sessionDidActivate():

public void sessionDidActivate(HttpSessionEvent se) {
  if (log==null)
    log = LogFactory.getLog(this.getClass());
}

public void sessionWillPassivate (HttpSessionEvent se) {
  ; /* Nothing to do */
}


-Tim

Antony Paul wrote:

> Then it throws NullPointerException
>
> rgds
> Antony Paul
>
> ----- Original Message -----
> From: "Shapira, Yoav" <Yoav.Shapira@mpi.com>
> To: "Tomcat Users List" <tomcat-user@jakarta.apache.org>
> Sent: Wednesday, September 15, 2004 6:05 PM
> Subject: RE: Serializable Logging implementation
>
>
>
> Hi,
> Hmm, you want to be careful with this pattern.  I like the private
> static one for Loggers -- there are very good reasons it's the
> recommended pattern (by log4j, by the java.util.logging folks) and the
> one that's used (by Tomcat and most other serious apps I know of).
>
> If you really want to stick with your "base class gets the logger"
> pattern, consider marking it as transient.
>
> Yoav Shapira
> Millennium Research Informatics
>
>
>
>> -----Original Message-----
>> From: Antony Paul [mailto:antonypaul24@hotmail.com]
>> Sent: Wednesday, September 15, 2004 8:27 AM
>> To: Tomcat Users List
>> Subject: Re: Serializable Logging implementation
>>
>> I extend a base form which gets the Log as
>> LogFactory.getLog(this.getClass());
>> So that no need to define and get a Log instance in subclass. Is there
>
>
> any
>
>> way so that I can follow this pattern.
>>
>> rgds
>> Antony Paul
>>
>> ----- Original Message -----
>> From: "Tim Funk" <funkman@joedog.org>
>> To: "Tomcat Users List" <tomcat-user@jakarta.apache.org>
>> Sent: Wednesday, September 15, 2004 4:38 PM
>> Subject: Re: Serializable Logging implementation
>>
>>
>>
>>> logging instances should be static to the class.
>>>
>>> // Commons logging example but a log4j equiv should be easy to find
>>>     private static Log log = LogFactory.getLog(MyClass.class);
>>>
>>>
>>> -Tim
>>>
>>> Antony Paul wrote:
>>>
>>>
>>>> Hi,
>>>>    I used Log4J and commons logging in an ActionForm which is
>>>
>
> stored
>
>> in
>> the
>>
>>>> session. When I reload the context it is invalidating the session
>>>
>>
>> because it
>>
>>>> is non serializable. Is there any work around for this ?. Or do I
>>>
>
> have
>
>> to
>>
>>>> use any other Logger.
>>>>


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message