Hi,
Wow, a new log *file* for every request?  Do you really want to be
looking at that many log files?  Anyways, here's are a couple of ideas:

- Create the log file programmatically each time:

This is in your service() method, or doGet() or doPost(), whichever is
relevant to your design.

  // Create a new appender, use current date to ensure uniqueness
  Layout fileLayout = new PatternLayout("...");
  String filePath = getServletContext().getRealPath("/logs") + new
Date().toString();
  Appender reqAppender = new FileAppender(fileLayout, filePath);

  // Get logger specific to this request, again using date
  Logger logger = Logger.getLogger(MyServlet.class.getName() + new
Date().toString());
  logger.addAppender(reqAppender);
  logger.setAdditivity(false);

  // Use the logger from now on...

- A couple of improvements to the above scheme:

  - Don't create a new layout each time.  Create once and save
somewhere, both to save space and to ensure all these files have the
same layout.
 
  - Maybe have all that stuff in a Filter that does the above processing
before the servlets get it.  Then you can take that code (which would
have to be in every servlet) out of the servlets and put it in one
place, the filter.

That said, I don't like this whole scheme of one log file per request,
but it's your app ;)

Yoav Shapira
Millennium ChemInformatics


>-----Original Message-----
>From: s s [mailto:[EMAIL PROTECTED]]
>Sent: Tuesday, July 30, 2002 5:43 PM
>To: [EMAIL PROTECTED]
>Subject: servlet logging
>
>
>Hi
>
>I am new to log4j so this may sound a naive question. I am wondering
what
>is the best way to create new log file for every single request for a
>servelet based webapp. Can somebody suggest a code example & sample
log4j
>configuration file?
>
>Thanks
>
>Dcol
>
>
>
>---------------------------------
>Do You Yahoo!?
>Yahoo! Health - Feel better, live better

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

Reply via email to