Re: Questions on logging

2004-08-31 Thread Nicolas De Loof


1. thread-safe require no variable (instance or static) that a thread may consider to
be the only one to update. Read-only member (as a logger instance) can be used safely.

2. you can configure log4j to add the thread id to the log, so that a simple grep will 
extract all logs for a request.

3. other classes can be used as you designed them. If they're creating a new instance 
for each request you will have no
thread-safe requirement to reach. If you use any singleton or static method you may 
have to take threads into account.

Nico.


 Hi

 I am in the stage of implementing logging in my struts application. I
 have been reading online but have some questions unanswered.

 1. Action class should be thread-safe. Therefore no static variable, I
 should just use a non-static variable to hold my logger?

 2. In a multi-user web application, how can I keep logs from the same
 class (same execution thread or same user request) stays together? I
 envision them to be all messy in the log file when there's multiple user
 requesting for the same action class.

 3. About the thread safe issue with Actin class, that doesn't apply to
 the other classes that action execute right? Those are treated as normal
 java files.

 Thanks

 Sebastian


 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]



Our name has changed.  Please update your address book to the following format: 
[EMAIL PROTECTED].

This message contains information that may be privileged or confidential and is the 
property of the Capgemini Group. It is intended only for the person to whom it is 
addressed. If you are not the intended recipient,  you are not authorized to read, 
print, retain, copy, disseminate,  distribute, or use this message or any part 
thereof. If you receive this  message in error, please notify the sender immediately 
and delete all  copies of this message.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Questions on logging

2004-08-31 Thread Craig McClanahan
On 31 Aug 2004 15:43:29 +0800, Sebastian Ho
[EMAIL PROTECTED] wrote:
 Hi
 
 I am in the stage of implementing logging in my struts application. I
 have been reading online but have some questions unanswered.
 
 1. Action class should be thread-safe. Therefore no static variable, I
 should just use a non-static variable to hold my logger?
 

A more precise definition of the rule is no non-thread-safe static or
instance variables that attempt to maintain state associated with a
particlar request.  Log instances are OK based on that rule, because
they are both threadsafe and application-wide.

 2. In a multi-user web application, how can I keep logs from the same
 class (same execution thread or same user request) stays together? I
 envision them to be all messy in the log file when there's multiple user
 requesting for the same action class.

As Nico points out, you can get the thread id added, that doesn't help
segregate log messages by application.  A different strategy is to set
up a separate logging environment for each webapp -- details will be
in, for example, the Log4J information.

 3. About the thread safe issue with Actin class, that doesn't apply to
 the other classes that action execute right? Those are treated as normal
 java files.

Thread safety of the object instances you call depends on whether you
created a separate instance for each request, or are reusing the same
instance.  In the former case, you don't have to worry -- in the
latter case (say you grabbed some common utility object out of the
application scope attributes), then the class for the instance you are
calling does need to be worried about thread safety.

 
 Thanks
 
 Sebastian
 

Craig

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]