title: Log4j: One log file per request
body: <p>We have a weblogic batch application which processes multiple requests from consumers at the same time. We use log4j for logging puposes. Right now we log into a single log file for multiple requests. It becomes tedious to debug an issue for a given request as for all requests the logs are in a single file. </p>
  
  <p>So plan is to have one log file per request. The consumer sends a request ID for which processing has to be performed. Now, in reality there could be multiple consumers sending the request IDs to our application. So question is how to seggregate the log files based on the request.</p>
  
  <p>We cannot start &amp; stop the production server every time so the point in using an overridden file appender with date time stamp or request ID is ruled out. This is what is explained in  the article below:
  <a href="http://veerasundar.com/blog/2009/08/how-to-create-a-new-log-file-for-each-time-the-application-runs/" rel="nofollow noreferrer">http://veerasundar.com/blog/2009/08/how-to-create-a-new-log-file-for-each-time-the-application-runs/</a></p>
  
  <p>I also tried playing around with these alternatives:</p>
  
  <p><a href="http://cognitivecache.blogspot.com/2008/08/log4j-writing-to-dynamic-log-file-for.html" rel="nofollow noreferrer">http://cognitivecache.blogspot.com/2008/08/log4j-writing-to-dynamic-log-file-for.html</a> </p>
  
  <p><a href="http://www.mail-archive.com/log4j-user@logging.apache.org/msg05099.html" rel="nofollow noreferrer">http://www.mail-archive.com/log4j-user@logging.apache.org/msg05099.html</a> </p>
  
  <p>This approach gives the desired results but it does not work properly if multiple request are send at the same time. Due to some concurrency issues logs go here and there.</p>
  
  <p>I anticipate some help from you folks. Thanks in advance....</p>