logging-log4cxx-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maarten <maart...@dns.be>
Subject Re: A design problem!
Date Wed, 02 Nov 2005 08:29:03 GMT
Ken wrote:

>    Currently, My program have 1 thread deal with all clients request,
>...
>     Maarten's NDC suggestion is what I thought before. The problem is
>each client will have a series of request, each of them will last
>variable time. So NDC may overlap the log content.
>
I do not see the problem. You have one thread processing all incoming 
requests, as soon
as you know the client (say its ip address) you push that info in the NDC.
You then process the request and log as much as you like (the ip address 
will be appended)
When your code is finished with the request you pop the ip-address from 
the NDC (or clear the NDC).
It does not matter if next request is from same client or not, and it 
does not matter if this was the client's last request.
And it does not matter if you have one thread processing all requests, 
or a thread pool or one thread per client.
Just make sure that you remove the client-info from the NDC before you 
start processing another request.
Or am I missing something ?

while (serverRunning)
{
  Request req = getNextRequestFromWhateverClient();
  NDC::push (req.getIpAddress());
  logger->info ("processing " + req.toString() );
  process (req);
  NDC::pop();
} 

We have a ServletFilter (java) that does exactly this:  push the remote 
ip address in the NDC before processing the request
and remove it after processing. Works like a charm.

You can also have one appender that writes everything to one (rolling) 
file AND a SocketAppender that sends everything
to another process,  that process could then split your logs to 
different files, based on the NDC.

Maarten

Mime
View raw message