You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Michael Echerer <me...@tngtech.com> on 2004/09/05 16:53:00 UTC

Tapestry & Log4j question, best practices for logging in Tapestry?

Hi,

I'd like to use a log4j MDC to dump some client specific information, 
like IP address and things like that.

Where should I place the MDC code for that purpose.

I thought about extending the BaseEngine and have my custom one override 
the createRequestCycle method. E.g.:

public class MyEngine extends BaseEngine {
     protected IRequestCycle createRequestCycle(RequestContext context,
             IEngineService service,
             IMonitor monitor) {

         MDC.put("UserIP",context.getRequest().getRemoteAddr());

         return super.createRequestCycle(context, service, monitor);
     }


Is this feasable, or a bad idea?

I'm curious... What are others doing to perform logging/monitoring in 
Tapestry and where is it integrated best?

Cheers,
Michael

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


Re: Tapestry & Log4j question, best practices for logging in Tapestry?

Posted by Bryan Lewis <br...@maine.rr.com>.
It's safe to call getVisit().  The visit is an instance variable in the
Engine, so once you've got the engine you've got the visit.  Of course,
you'd want to check whether the visit is null.  Here's my code.

    protected void setupForRequest(RequestContext context)
    {
        super.setupForRequest(context);

        // Set this request's userName into the log4j context for logging.
        String userName = "";
        Visit visit = (Visit) getVisit();
        if (visit != null) {
            userName = visit.getUserName();
        }
        MDC.put("user", userName);
    }


----- Original Message ----- 
From: "Michael Echerer" <me...@tngtech.com>
To: "Tapestry users" <ta...@jakarta.apache.org>
Sent: Sunday, September 05, 2004 2:31 PM
Subject: Re: Tapestry & Log4j question, best practices for logging in
Tapestry?


> Thx, for this confirm. setupForRequest() seems to be the one to use,
> because the API doc mentions something about custom overrides. Only the
> Service name could be interesting & would only be available by using
> createRequestCycle()...
>
> One more question:
>
> Is it safe to call getVisit() in those methods already to obtain e.g.
> the logged-in user (as far as Visit already created) or does the init
> (guess it must be obtained from the HTTPSession somewhere by Tapestry)
> for the Visit object happen later?
>
> Cheers,
> Michael
>
> Bryan Lewis wrote:
>
> > Good idea.  This kind of logging has been very working well for me... I
put
> > the user's name in the MDC so that each line in the log shows which user
> > it's for.  My custom Engine overrides setupForRequest() to do this, but
> > createRequestCycle() appears to be equally good; both methods are called
> > from service().
> >
> >
> > ----- Original Message ----- 
> > From: "Michael Echerer" <me...@tngtech.com>
> > To: "Tapestry users" <ta...@jakarta.apache.org>
> > Sent: Sunday, September 05, 2004 10:53 AM
> > Subject: Tapestry & Log4j question, best practices for logging in
Tapestry?
> >
> >
> >
> >>Hi,
> >>
> >>I'd like to use a log4j MDC to dump some client specific information,
> >>like IP address and things like that.
> >>
> >>Where should I place the MDC code for that purpose.
> >>
> >>I thought about extending the BaseEngine and have my custom one override
> >>the createRequestCycle method. E.g.:
> >>
> >>public class MyEngine extends BaseEngine {
> >>     protected IRequestCycle createRequestCycle(RequestContext context,
> >>             IEngineService service,
> >>             IMonitor monitor) {
> >>
> >>         MDC.put("UserIP",context.getRequest().getRemoteAddr());
> >>
> >>         return super.createRequestCycle(context, service, monitor);
> >>     }
> >>
> >>
> >>Is this feasable, or a bad idea?
> >>
> >>I'm curious... What are others doing to perform logging/monitoring in
> >>Tapestry and where is it integrated best?
> >>
> >>Cheers,
> >>Michael
> >>
> >>---------------------------------------------------------------------
> >>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> >>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> >>
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>


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


Re: Tapestry & Log4j question, best practices for logging in Tapestry?

Posted by Michael Echerer <me...@tngtech.com>.
Thx, for this confirm. setupForRequest() seems to be the one to use, 
because the API doc mentions something about custom overrides. Only the 
Service name could be interesting & would only be available by using 
createRequestCycle()...

One more question:

Is it safe to call getVisit() in those methods already to obtain e.g. 
the logged-in user (as far as Visit already created) or does the init 
(guess it must be obtained from the HTTPSession somewhere by Tapestry) 
for the Visit object happen later?

Cheers,
Michael

Bryan Lewis wrote:

> Good idea.  This kind of logging has been very working well for me... I put
> the user's name in the MDC so that each line in the log shows which user
> it's for.  My custom Engine overrides setupForRequest() to do this, but
> createRequestCycle() appears to be equally good; both methods are called
> from service().
> 
> 
> ----- Original Message ----- 
> From: "Michael Echerer" <me...@tngtech.com>
> To: "Tapestry users" <ta...@jakarta.apache.org>
> Sent: Sunday, September 05, 2004 10:53 AM
> Subject: Tapestry & Log4j question, best practices for logging in Tapestry?
> 
> 
> 
>>Hi,
>>
>>I'd like to use a log4j MDC to dump some client specific information,
>>like IP address and things like that.
>>
>>Where should I place the MDC code for that purpose.
>>
>>I thought about extending the BaseEngine and have my custom one override
>>the createRequestCycle method. E.g.:
>>
>>public class MyEngine extends BaseEngine {
>>     protected IRequestCycle createRequestCycle(RequestContext context,
>>             IEngineService service,
>>             IMonitor monitor) {
>>
>>         MDC.put("UserIP",context.getRequest().getRemoteAddr());
>>
>>         return super.createRequestCycle(context, service, monitor);
>>     }
>>
>>
>>Is this feasable, or a bad idea?
>>
>>I'm curious... What are others doing to perform logging/monitoring in
>>Tapestry and where is it integrated best?
>>
>>Cheers,
>>Michael
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> 
> 

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


Re: Tapestry & Log4j question, best practices for logging in Tapestry?

Posted by Bryan Lewis <br...@maine.rr.com>.
Good idea.  This kind of logging has been very working well for me... I put
the user's name in the MDC so that each line in the log shows which user
it's for.  My custom Engine overrides setupForRequest() to do this, but
createRequestCycle() appears to be equally good; both methods are called
from service().


----- Original Message ----- 
From: "Michael Echerer" <me...@tngtech.com>
To: "Tapestry users" <ta...@jakarta.apache.org>
Sent: Sunday, September 05, 2004 10:53 AM
Subject: Tapestry & Log4j question, best practices for logging in Tapestry?


> Hi,
>
> I'd like to use a log4j MDC to dump some client specific information,
> like IP address and things like that.
>
> Where should I place the MDC code for that purpose.
>
> I thought about extending the BaseEngine and have my custom one override
> the createRequestCycle method. E.g.:
>
> public class MyEngine extends BaseEngine {
>      protected IRequestCycle createRequestCycle(RequestContext context,
>              IEngineService service,
>              IMonitor monitor) {
>
>          MDC.put("UserIP",context.getRequest().getRemoteAddr());
>
>          return super.createRequestCycle(context, service, monitor);
>      }
>
>
> Is this feasable, or a bad idea?
>
> I'm curious... What are others doing to perform logging/monitoring in
> Tapestry and where is it integrated best?
>
> Cheers,
> Michael
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>


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