At 21:02 23.04.2004, Ceki Gülcü wrote:
>At 09:58 AM 4/20/2004, Stefan Preuss wrote:
>>Helo,
>>
>>I'm developing an Web application based on JSP/Servlet/Bean. Up to now I'm using my 
>>own logger(s). Now I want to take advantage of log4j.
>>
>>For some simple java tools I changed before, log4j works fine. But in this case I 
>>have some trouble with the logging on server side.
>>
>>The application uses a session concept. The user starts with a login page (a 
>>servlet) which do some initial stuff. Then, when she entered her name and password 
>>the request is send to the menu (JSP) which uses a session bean what does the login. 
>>Now she starts working on many JSPs and servlets... finally the logout page 
>>(servlet) is called to cleanup all beans and remove them from session context. So, 
>>that's what it does.
>>
>>Now what I want to do:
>>The login page does not know any about the user who is visiting it (and don't need 
>>to). All logging requests until the session bean successfully left the login should 
>>be directed to one file. So it is quiet easy to analyze the login process. To keep 
>>apart multiple requests at the same time from different clients, the HTTP session id 
>>should be logged.
>>All user action between login and logout are to be directed to a separate file (one 
>>for each user and each session). The bulk of files are structured by creating sub 
>>directories for each user.
>>
>>My attempt was to use MDC to put some properties (HTTP session id and user id) on 
>>the thread that executes the current request. I wrote my own appender that holds a 
>>hash table with file appenders associated by combination of session and user id. 
>>Depending on the mentioned properties my appender gets the file appender from the 
>>hash and redirects the logging event to it. All was fine until I noticed that the 
>>servlet container (I was using tomact 3.3.1a - but WebLogic, WebSphere and JBoss has 
>>to be supported too) reuses the threads. Due to the fact that I didn't remove the 
>>user id from the thread after the request finished, the request of another client 
>>which has not yet logged in uses the same thread and logs with the wrong user id.
>>
>>Now I guess, if I want to use MDC for this issue I have to put and remove the 
>>properties (session and user id) in each and every JSP and servlet (about three 
>>dozens)? Is there now simpler way? I think this is some error-prone, if I forget to 
>>remove the properties...
>>
>>I already thought about javax.servlet.Filter, but this is first available since 
>>Servelt API 2.3. I have to support 2.2. Another thought was to have my own "Filter" 
>>by implementing a servlet which proxies all request and do the MDC.put and 
>>MDC.remove at its request handling... But isn't this somewhat disproportionate - 
>>"just for logging" ???
>
>Filters can provide a robust solution. In general, any interception mechanism that 
>allows you to set the MDC when starting to serve an incoming request and clearing the 
>MDC when done serving, should do the job. Struts plug-ins, JBoss interceptors, or 
>Tomcat valves would do the job although I'd just stick with filters...

Well, as mentioned, I already thought about filters, but they are not available for 
Servlet API 2.2 (Tomcat 3, WebLogic 5, ...).


>>I hope that I was doing the wrong way so far, and anyone out there has an ingenious 
>>idea to do session logging with log4j. Otherwise it is really hard to do this with 
>>log4j, I think.
>
>It's more of an interception problem rather then a log4j issue. Wouldn't you think?

That's right. I will take a look for JBoss interceptors and Tomcat valves, but I don't 
like the thought to use vendor specific stuff.


>>Thanks and best regards
>>Stefan
>>
>>
>>___________________________________
>>Stefan Preuss
>>PROSTEP GIDA GmbH
>>Albert-Einstein-Str. 16
>>D-12489 Berlin
>>
>>Email: [EMAIL PROTECTED]
>>___________________________________
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: [EMAIL PROTECTED]
>>For additional commands, e-mail: [EMAIL PROTECTED]
>
>-- 
>Ceki Gülcü
>
>     For log4j documentation consider "The complete log4j manual"
>     ISBN: 2970036908 http://www.qos.ch/shop/products/clm_t.jsp  
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]

Thanks.
Stefan


___________________________________
Stefan Preuss
PROSTEP GIDA GmbH
Albert-Einstein-Str. 16
D-12489 Berlin

Email: [EMAIL PROTECTED]
___________________________________


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

Reply via email to