You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Francois Meillet <fr...@gmail.com> on 2016/02/17 14:34:22 UTC

log4j MDC IRequestLogger

Dear All,

I use the Mapped Diagnostic Context concept https://logging.apache.org/log4j/2.x/manual/thread-context.html).

Using log4j 2.x and a specific AbstractRequestCycleListener, 
I overrided onBeginRequest() to perform a ThreadContext.push(id) 
and onDetach(RequestCycle cycle) to perform a ThreadContext.pop();.

So far so good for all the logs but the IRequestLogger's logs.

I notice that the IRequestLogger # performLogging() is called after the RequestCycle # onDetach() has been called.

I would like it to happen before !
Is that possible ? 


François 



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: log4j MDC IRequestLogger

Posted by mscoon <ms...@gmail.com>.
Hi,

In a similar situation we have sub-classed RequestLogger and we are
clearing the thread context in the end of MyRequestLogger.log(), so that
the thread context is available when super.log() is called. It is not as
clean as using AbstractRequestCycleListener.onDetach, but it works.

Marios

On Wed, Feb 17, 2016 at 3:34 PM, Francois Meillet <
francois.meillet@gmail.com> wrote:

> Dear All,
>
> I use the Mapped Diagnostic Context concept
> https://logging.apache.org/log4j/2.x/manual/thread-context.html).
>
> Using log4j 2.x and a specific AbstractRequestCycleListener,
> I overrided onBeginRequest() to perform a ThreadContext.push(id)
> and onDetach(RequestCycle cycle) to perform a ThreadContext.pop();.
>
> So far so good for all the logs but the IRequestLogger's logs.
>
> I notice that the IRequestLogger # performLogging() is called after the
> RequestCycle # onDetach() has been called.
>
> I would like it to happen before !
> Is that possible ?
>
>
> François
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: log4j MDC IRequestLogger

Posted by Francois Meillet <fr...@gmail.com>.
Thanks Marios and Martin,

François 








Le 18 févr. 2016 à 08:17, Martin Grigorov <mg...@apache.org> a écrit :

> Hi Francois,
> 
> You can create a custom RequestLogger that just calls
> super.performLogging() and pops the context.
> Setup it with org.apache.wicket.Application#newRequestLogger()
> 
> Martin Grigorov
> Wicket Training and Consulting
> https://twitter.com/mtgrigorov
> 
> On Wed, Feb 17, 2016 at 2:34 PM, Francois Meillet <
> francois.meillet@gmail.com> wrote:
> 
>> Dear All,
>> 
>> I use the Mapped Diagnostic Context concept
>> https://logging.apache.org/log4j/2.x/manual/thread-context.html).
>> 
>> Using log4j 2.x and a specific AbstractRequestCycleListener,
>> I overrided onBeginRequest() to perform a ThreadContext.push(id)
>> and onDetach(RequestCycle cycle) to perform a ThreadContext.pop();.
>> 
>> So far so good for all the logs but the IRequestLogger's logs.
>> 
>> I notice that the IRequestLogger # performLogging() is called after the
>> RequestCycle # onDetach() has been called.
>> 
>> I would like it to happen before !
>> Is that possible ?
>> 
>> 
>> François
>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>> 
>> 


Re: log4j MDC IRequestLogger

Posted by Francois Meillet <fr...@gmail.com>.
I ended up with a custom RequestCycle

@Override
public boolean processRequestAndDetach() {

    boolean result;
    try {
        result = processRequest();
    } finally {
        detach();
    }

    popMDC();

    return result;
}

@Override
protected void onBeginRequest()
{
    pushMDC();
}


François 








Le 18 févr. 2016 à 08:17, Martin Grigorov <mg...@apache.org> a écrit :

> Hi Francois,
> 
> You can create a custom RequestLogger that just calls
> super.performLogging() and pops the context.
> Setup it with org.apache.wicket.Application#newRequestLogger()
> 
> Martin Grigorov
> Wicket Training and Consulting
> https://twitter.com/mtgrigorov
> 
> On Wed, Feb 17, 2016 at 2:34 PM, Francois Meillet <
> francois.meillet@gmail.com> wrote:
> 
>> Dear All,
>> 
>> I use the Mapped Diagnostic Context concept
>> https://logging.apache.org/log4j/2.x/manual/thread-context.html).
>> 
>> Using log4j 2.x and a specific AbstractRequestCycleListener,
>> I overrided onBeginRequest() to perform a ThreadContext.push(id)
>> and onDetach(RequestCycle cycle) to perform a ThreadContext.pop();.
>> 
>> So far so good for all the logs but the IRequestLogger's logs.
>> 
>> I notice that the IRequestLogger # performLogging() is called after the
>> RequestCycle # onDetach() has been called.
>> 
>> I would like it to happen before !
>> Is that possible ?
>> 
>> 
>> François
>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>> 
>> 


Re: log4j MDC IRequestLogger

Posted by Martin Grigorov <mg...@apache.org>.
Hi Francois,

You can create a custom RequestLogger that just calls
super.performLogging() and pops the context.
Setup it with org.apache.wicket.Application#newRequestLogger()

Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Wed, Feb 17, 2016 at 2:34 PM, Francois Meillet <
francois.meillet@gmail.com> wrote:

> Dear All,
>
> I use the Mapped Diagnostic Context concept
> https://logging.apache.org/log4j/2.x/manual/thread-context.html).
>
> Using log4j 2.x and a specific AbstractRequestCycleListener,
> I overrided onBeginRequest() to perform a ThreadContext.push(id)
> and onDetach(RequestCycle cycle) to perform a ThreadContext.pop();.
>
> So far so good for all the logs but the IRequestLogger's logs.
>
> I notice that the IRequestLogger # performLogging() is called after the
> RequestCycle # onDetach() has been called.
>
> I would like it to happen before !
> Is that possible ?
>
>
> François
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>