RE: Serializable Logging implementation
Hi, Ditch the super class philosphy. And copy the following 3 lines of code: import ... LogFactory; import ... Log; private static log = LogFactory.get...(My.class); Yup, exactly. Tim's message is right on, and if you look at the start of this thread you see we only started suggesting the alternative approaches (transient, activation listener) when the OP wanted to stick to his bad design pattern. Yoav This e-mail, including any attachments, is a confidential business communication, and may contain information that is confidential, proprietary and/or privileged. This e-mail is intended only for the individual(s) to whom it is addressed, and may not be saved, copied, printed, disclosed or used by anyone else. If you are not the(an) intended recipient, please immediately delete this e-mail from your computer system and notify the sender. Thank you. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Serializable Logging implementation
static variables are not serialized because they are not part of the object instance being serialized. (Can thing of a better phrasing) -Tim Spiegs wrote: Ok, in a nutshell - using a private static logger in each model object will not be serialized across the cluster. Use the following 3 lines of code you provided and I won't have any problems with the log4j log instance not being serializable, because it never will be. Right? (I'm not familiar with how the Classloader handles static variables in a clustered environment) Thanks, Eric Original Message -- Ditch the super class philosphy. And copy the following 3 lines of code: import ... LogFactory; import ... Log; private static log = LogFactory.get...(My.class); You don't want to use the super class philophy because debugging the inheritance chain becomes impossible. For example: SuperClass SubClass SubSubClass SubSubSubClass With a log variable at the Super class level inherited by the sub classes, it is IMPOSSIBLE to debug SubClass or SubSubClass. (As well as SuperClass) For example - I might want trace turned on for the super class and warn on for the rest of the classes in the hierarchy. Inheritance kills any chance of fine grained control of log output. If it's static - it can't be transient. And all the instances share all the same log instance at the Classloader level so it is never serialized. -Tim - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Serializable Logging implementation
What is OP ? Can you please expand it ? rgds Antony Paul - Original Message - From: Shapira, Yoav [EMAIL PROTECTED] To: Tomcat Users List [EMAIL PROTECTED] Sent: Friday, September 17, 2004 5:41 PM Subject: RE: Serializable Logging implementation Hi, Ditch the super class philosphy. And copy the following 3 lines of code: import ... LogFactory; import ... Log; private static log = LogFactory.get...(My.class); Yup, exactly. Tim's message is right on, and if you look at the start of this thread you see we only started suggesting the alternative approaches (transient, activation listener) when the OP wanted to stick to his bad design pattern. Yoav This e-mail, including any attachments, is a confidential business communication, and may contain information that is confidential, proprietary and/or privileged. This e-mail is intended only for the individual(s) to whom it is addressed, and may not be saved, copied, printed, disclosed or used by anyone else. If you are not the(an) intended recipient, please immediately delete this e-mail from your computer system and notify the sender. Thank you. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Serializable Logging implementation
Hi, OP = Original Poster, the person who started this thread. Yoav Shapira Millennium Research Informatics -Original Message- From: Antony Paul [mailto:[EMAIL PROTECTED] Sent: Friday, September 17, 2004 9:31 AM To: Tomcat Users List Subject: Re: Serializable Logging implementation What is OP ? Can you please expand it ? rgds Antony Paul - Original Message - From: Shapira, Yoav [EMAIL PROTECTED] To: Tomcat Users List [EMAIL PROTECTED] Sent: Friday, September 17, 2004 5:41 PM Subject: RE: Serializable Logging implementation Hi, Ditch the super class philosphy. And copy the following 3 lines of code: import ... LogFactory; import ... Log; private static log = LogFactory.get...(My.class); Yup, exactly. Tim's message is right on, and if you look at the start of this thread you see we only started suggesting the alternative approaches (transient, activation listener) when the OP wanted to stick to his bad design pattern. Yoav This e-mail, including any attachments, is a confidential business communication, and may contain information that is confidential, proprietary and/or privileged. This e-mail is intended only for the individual(s) to whom it is addressed, and may not be saved, copied, printed, disclosed or used by anyone else. If you are not the(an) intended recipient, please immediately delete this e-mail from your computer system and notify the sender. Thank you. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] This e-mail, including any attachments, is a confidential business communication, and may contain information that is confidential, proprietary and/or privileged. This e-mail is intended only for the individual(s) to whom it is addressed, and may not be saved, copied, printed, disclosed or used by anyone else. If you are not the(an) intended recipient, please immediately delete this e-mail from your computer system and notify the sender. Thank you. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Serializable Logging implementation
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 [EMAIL PROTECTED] Date: Wed, 15 Sep 2004 09:20:06 -0400 To: Tomcat Users List [EMAIL PROTECTED] 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 [EMAIL PROTECTED] To: Tomcat Users List [EMAIL PROTECTED] 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:[EMAIL PROTECTED] 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 [EMAIL PROTECTED] To: Tomcat Users List [EMAIL PROTECTED] 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.
Re: Serializable Logging implementation
Ditch the super class philosphy. And copy the following 3 lines of code: import ... LogFactory; import ... Log; private static log = LogFactory.get...(My.class); You don't want to use the super class philophy because debugging the inheritance chain becomes impossible. For example: SuperClass SubClass SubSubClass SubSubSubClass With a log variable at the Super class level inherited by the sub classes, it is IMPOSSIBLE to debug SubClass or SubSubClass. (As well as SuperClass) For example - I might want trace turned on for the super class and warn on for the rest of the classes in the hierarchy. Inheritance kills any chance of fine grained control of log output. If it's static - it can't be transient. And all the instances share all the same log instance at the Classloader level so it is never serialized. -Tim Spiegs wrote: 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 [EMAIL PROTECTED] Date: Wed, 15 Sep 2004 09:20:06 -0400 To: Tomcat Users List [EMAIL PROTECTED] 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 [EMAIL PROTECTED] To: Tomcat Users List [EMAIL PROTECTED] 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:[EMAIL PROTECTED] 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 [EMAIL PROTECTED] To: Tomcat Users List [EMAIL PROTECTED] 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. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Serializable Logging implementation
Ok, in a nutshell - using a private static logger in each model object will not be serialized across the cluster. Use the following 3 lines of code you provided and I won't have any problems with the log4j log instance not being serializable, because it never will be. Right? (I'm not familiar with how the Classloader handles static variables in a clustered environment) Thanks, Eric Original Message -- Ditch the super class philosphy. And copy the following 3 lines of code: import ... LogFactory; import ... Log; private static log = LogFactory.get...(My.class); You don't want to use the super class philophy because debugging the inheritance chain becomes impossible. For example: SuperClass SubClass SubSubClass SubSubSubClass With a log variable at the Super class level inherited by the sub classes, it is IMPOSSIBLE to debug SubClass or SubSubClass. (As well as SuperClass) For example - I might want trace turned on for the super class and warn on for the rest of the classes in the hierarchy. Inheritance kills any chance of fine grained control of log output. If it's static - it can't be transient. And all the instances share all the same log instance at the Classloader level so it is never serialized. -Tim - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Serializable Logging implementation
On Thu, Sep 16, 2004 at 07:49:17PM -0500, Spiegs wrote: : 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? What about, don't store model objects[1] in session (or anyplace else that may be serialized)? If you're passing data around, use a DTO. Whether to use DTOs is something of a religious issue; but pure data-holders rarely need internal logging. If client code wants to log a value they fetch out of a DTO, let them have at it... -QM [1] = This statement assumes any model object that requires internal logging is much more than a pure data-holder. -- software -- http://www.brandxdev.net tech news -- http://www.RoarNetworX.com - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Serializable Logging implementation
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. rgds Antony Paul - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
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. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
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 [EMAIL PROTECTED] To: Tomcat Users List [EMAIL PROTECTED] 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. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
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:[EMAIL PROTECTED] 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 [EMAIL PROTECTED] To: Tomcat Users List [EMAIL PROTECTED] 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. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] This e-mail, including any attachments, is a confidential business communication, and may contain information that is confidential, proprietary and/or privileged. This e-mail is intended only for the individual(s) to whom it is addressed, and may not be saved, copied, printed, disclosed or used by anyone else. If you are not the(an) intended recipient, please immediately delete this e-mail from your computer system and notify the sender. Thank you. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Serializable Logging implementation
Then it throws NullPointerException rgds Antony Paul - Original Message - From: Shapira, Yoav [EMAIL PROTECTED] To: Tomcat Users List [EMAIL PROTECTED] 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:[EMAIL PROTECTED] 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 [EMAIL PROTECTED] To: Tomcat Users List [EMAIL PROTECTED] 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. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] This e-mail, including any attachments, is a confidential business communication, and may contain information that is confidential, proprietary and/or privileged. This e-mail is intended only for the individual(s) to whom it is addressed, and may not be saved, copied, printed, disclosed or used by anyone else. If you are not the(an) intended recipient, please immediately delete this e-mail from your computer system and notify the sender. Thank you. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Serializable Logging implementation
Hi, Then no one can help you if you don't give any details ;) Stack trace? Config details? Have you done any debugging of your own? NPEs usually take about a minute to resolve, much shorter than writing a message to this list and waiting for a response... Why don't people get this lesson? It's repeated at least once a day on this list ;) Yoav Shapira Millennium Research Informatics -Original Message- From: Antony Paul [mailto:[EMAIL PROTECTED] Sent: Wednesday, September 15, 2004 9:04 AM To: Tomcat Users List Subject: Re: Serializable Logging implementation Then it throws NullPointerException rgds Antony Paul - Original Message - From: Shapira, Yoav [EMAIL PROTECTED] To: Tomcat Users List [EMAIL PROTECTED] 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:[EMAIL PROTECTED] 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 [EMAIL PROTECTED] To: Tomcat Users List [EMAIL PROTECTED] 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. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] This e-mail, including any attachments, is a confidential business communication, and may contain information that is confidential, proprietary and/or privileged. This e-mail is intended only for the individual(s) to whom it is addressed, and may not be saved, copied, printed, disclosed or used by anyone else. If you are not the(an) intended recipient, please immediately delete this e-mail from your computer system and notify the sender. Thank you. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] This e-mail, including any attachments, is a confidential business communication, and may contain information that is confidential, proprietary and/or privileged. This e-mail is intended only for the individual(s) to whom it is addressed, and may not be saved, copied, printed, disclosed or used by anyone else. If you are not the(an) intended recipient, please immediately delete this e-mail from your computer system and notify the sender. Thank you. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Serializable Logging implementation
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 [EMAIL PROTECTED] To: Tomcat Users List [EMAIL PROTECTED] 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:[EMAIL PROTECTED] 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 [EMAIL PROTECTED] To: Tomcat Users List [EMAIL PROTECTED] 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. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Serializable Logging implementation
The NPE is because the Log instance is transient. I can fix this by getting a new instance when it is read from disk. I dont remember the method which is called when an object is serialized. rgds Antony Paul - Original Message - From: Shapira, Yoav [EMAIL PROTECTED] To: Tomcat Users List [EMAIL PROTECTED] Sent: Wednesday, September 15, 2004 6:33 PM Subject: RE: Serializable Logging implementation Hi, Then no one can help you if you don't give any details ;) Stack trace? Config details? Have you done any debugging of your own? NPEs usually take about a minute to resolve, much shorter than writing a message to this list and waiting for a response... Why don't people get this lesson? It's repeated at least once a day on this list ;) Yoav Shapira Millennium Research Informatics -Original Message- From: Antony Paul [mailto:[EMAIL PROTECTED] Sent: Wednesday, September 15, 2004 9:04 AM To: Tomcat Users List Subject: Re: Serializable Logging implementation Then it throws NullPointerException rgds Antony Paul - Original Message - From: Shapira, Yoav [EMAIL PROTECTED] To: Tomcat Users List [EMAIL PROTECTED] 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:[EMAIL PROTECTED] 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 [EMAIL PROTECTED] To: Tomcat Users List [EMAIL PROTECTED] 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. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] This e-mail, including any attachments, is a confidential business communication, and may contain information that is confidential, proprietary and/or privileged. This e-mail is intended only for the individual(s) to whom it is addressed, and may not be saved, copied, printed, disclosed or used by anyone else. If you are not the(an) intended recipient, please immediately delete this e-mail from your computer system and notify the sender. Thank you. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] This e-mail, including any attachments, is a confidential business communication, and may contain information that is confidential, proprietary and/or privileged. This e-mail is intended only for the individual(s) to whom it is addressed, and may not be saved, copied, printed, disclosed or used by anyone else. If you are not the(an) intended recipient, please immediately delete this e-mail from your computer system and notify the sender. Thank you. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Serializable Logging implementation
My understanding is that this event will be called when the container passivates for transfering one object from one VM to Another like a cluster. Will this be invlked on Tomcat 4.1 when an object is serialised ?. rgds Antony Paul - Original Message - From: Tim Funk [EMAIL PROTECTED] To: Tomcat Users List [EMAIL PROTECTED] Sent: Wednesday, September 15, 2004 6:50 PM Subject: Re: Serializable Logging implementation 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 [EMAIL PROTECTED] To: Tomcat Users List [EMAIL PROTECTED] 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:[EMAIL PROTECTED] 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 [EMAIL PROTECTED] To: Tomcat Users List [EMAIL PROTECTED] 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. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Serializable Logging implementation
The NPE is because the Log instance is transient. I can fix this by getting a new instance when it is read from disk. I dont remember the method which is called when an object is serialized. rgds Antony Paul - Original Message - From: Shapira, Yoav [EMAIL PROTECTED] To: Tomcat Users List [EMAIL PROTECTED] Sent: Wednesday, September 15, 2004 6:33 PM Subject: RE: Serializable Logging implementation Hi, Then no one can help you if you don't give any details ;) Stack trace? Config details? Have you done any debugging of your own? NPEs usually take about a minute to resolve, much shorter than writing a message to this list and waiting for a response... Why don't people get this lesson? It's repeated at least once a day on this list ;) Yoav Shapira Millennium Research Informatics -Original Message- From: Antony Paul [mailto:[EMAIL PROTECTED] Sent: Wednesday, September 15, 2004 9:04 AM To: Tomcat Users List Subject: Re: Serializable Logging implementation Then it throws NullPointerException rgds Antony Paul - Original Message - From: Shapira, Yoav [EMAIL PROTECTED] To: Tomcat Users List [EMAIL PROTECTED] 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:[EMAIL PROTECTED] 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 [EMAIL PROTECTED] To: Tomcat Users List [EMAIL PROTECTED] 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. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] This e-mail, including any attachments, is a confidential business communication, and may contain information that is confidential, proprietary and/or privileged. This e-mail is intended only for the individual(s) to whom it is addressed, and may not be saved, copied, printed, disclosed or used by anyone else. If you are not the(an) intended recipient, please immediately delete this e-mail from your computer system and notify the sender. Thank you. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] This e-mail, including any attachments, is a confidential business communication, and may contain information that is confidential, proprietary and/or privileged. This e-mail is intended only for the individual(s) to whom it is addressed, and may not be saved, copied, printed, disclosed or used by anyone else. If you are not the(an) intended recipient, please immediately delete this e-mail from your computer system and notify the sender. Thank you. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Serializable Logging implementation
Yes -Tim Antony Paul wrote: My understanding is that this event will be called when the container passivates for transfering one object from one VM to Another like a cluster. Will this be invlked on Tomcat 4.1 when an object is serialised ?. rgds Antony Paul - Original Message - From: Tim Funk [EMAIL PROTECTED] To: Tomcat Users List [EMAIL PROTECTED] Sent: Wednesday, September 15, 2004 6:50 PM Subject: Re: Serializable Logging implementation 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 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Serializable Logging implementation
Quoting Tim Funk [EMAIL PROTECTED]: 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); or private transient Log log = LogFactory.getLog(MyClass.class); Although this would mean a new instance of the log variable for every instance of the class. The static version is the better idea in most cases. Jake -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. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]