Of course. MDC content is kept on a per thread basis. Since each session is 
handled in its own thread, you can put a value into the MDC  somewhere at the 
entry point of a session (and remove it again when session is finished). The 
formatter of log4j (at least the PatternLayout) can retrieve this value by 
"%X{sessionID}" where "sessionID" is the name of the variable you have putted 
to MDC.
Heri

-----Ursprüngliche Nachricht-----
Von: Renan Vinícius Mozone [mailto:renan.moz...@gmail.com] 
Gesendet: Mittwoch, 30. September 2009 21:08
An: log4j-user@logging.apache.org
Betreff: Re: Log session session information (Web)

    Dear Matt Brown,
    My JSP application also uses some Java classes. Your solution is suitable 
for use inside those Java classes?

On Wed, Sep 30, 2009 at 15:40, Matt Brown <matt.br...@citrixonline.com>wrote:

> I've implemented this before by writing a javax.servlet.Filter to add 
> the SessionID to the MDC of every request.
>
> -----Original Message-----
> From: Renan Vinícius Mozone [mailto:renan.moz...@gmail.com]
> Sent: Wednesday, September 30, 2009 2:13 PM
> To: log4j-user@logging.apache.org
> Subject: Log session session information (Web)
>
>    I'm planning to use log4j on a JSP based application. However, 
> every log entry must have a session identification. This session 
> identification is in a session variable.
>    How can I configure the formatter to achieve this?
>
>    The log entry must be something like this:
>
>    [TIMESTAMP] [THREAD] [LOG LEVEL] [SESSION ID] [MESSAGE]
>
>    Thanks in advance.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
> For additional commands, e-mail: log4j-user-h...@logging.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-user-h...@logging.apache.org

Reply via email to