You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Renan Vinícius Mozone <re...@gmail.com> on 2009/09/30 20:12:56 UTC

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.

AW: Log session session information (Web)

Posted by Bender Heri <hb...@ergonomics.ch>.
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.mozone@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 <Ma...@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.mozone@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-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>

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


Re: Log session session information (Web)

Posted by Renan Vinícius Mozone <re...@gmail.com>.
    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 <Ma...@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.mozone@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-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>

RE: Log session session information (Web)

Posted by Matt Brown <Ma...@citrixOnline.com>.
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.mozone@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-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org