Shaligram,

hmm. I would make sure that your Servlet engine is has not been configured to run using a SingleThreadedModel as the NDC is maintained on a thread-by-thread basis.

For what it is worth, I have had good success using the mapped diagnostic context (MDC) for this purpose... and for what its worth, I usually place a Servlet Filter in front of my Struts action controller to do push/pop, as it is less invasive than tweaking the actual struts classes, and allows for easier inclusion of 3rd party struts-related code (like Struts Scaffold, for example)

Ex:

public class AuditFilter implements Filter
{
 ...

 public void doFilter(ServletRequest a_request, ServletResponse a_response,
     FilterChain a_chain) throws IOException, ServletException
 {

try {

HttpServletRequest httpReq = (HttpServletRequest) a_request;
org.apache.log4j.MDC.put("username", httpReq.getUserPrincipal().getName());


     // Pass control on to the next filter
     a_chain.doFilter(a_request, a_response);
   }
   finally {
     org.apache.log4j.MDC.remove("username");
   }
 }

}

Also, I do the same sort of thing on the EJB side by getting the Principal from the EJB context and pushing it into the MDC in each remote/local interface (a necessary evil, unless you are using AspectJ or something to perform this step automagically)

Hope it helps,

-don



At 12:08 PM 8/15/2003 -0400, Digambar, Shaligram (Consultant) wrote:

Hello,
In our web application we have a JSP->Struts->EJB->Database dataFlow for
each user. I am using log4j for logging the data to a log file and
logFactor5 to display log from the log file. I am interested in sorting the
logs for each user based on the user ID. Mulitple users can log into the web
app at same time from different browsers. Currently the NDC is implemented
as below
->in login action servelet write NDC.push(userID)
->log debug messages in other JSPs and Actions and EJBs
->in logoff action write NDC.pop(), NDC.remove()

This works well for one user e.g. it produces output like user123,"debug
message1"; user123 "infomessage1"   and so on.
The problem comes when another user say userABC logs in while user123 is
still logged in. The output log looks like user123 user456,"debug message1";
user123 user456,"infomessage1"   and so on.

I need a separate log record for each userID and I need to differentiate the
log records based on the userID. How can I accomplish that? Since the NDC
stack is global, it gets appeded for each user if the previous user is not
popped. Is there any other way to implement this?

Thanks,
Shaligram

Phone: (401)392-7948
Fax:(401)392-4974/4975



-----------------------------------------
This email may contain confidential and privileged material for the sole use of the intended recipient(s). Any review, use, retention, distribution or disclosure by others is strictly prohibited. If you are not the intended recipient (or authorized to receive for the recipient), please contact the sender by reply email and delete all copies of this message. Also, email is susceptible to data corruption, interception, tampering, unauthorized amendment and viruses. We only send and receive emails on the basis that we are not liable for any such corruption, interception, tampering, amendment or viruses or any consequence thereof.



--------------------------------------------------------------------- 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]



Reply via email to