You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by Paul Sowden <ps...@gmail.com> on 2015/10/28 11:56:00 UTC

Applying MDC to stacktraces

Hi folks,

I'm looking to migrate from log4j1 to 2 and i'm wondering if there's any
way of making MDC prefixes appear on all stack trace lines. In 1 I had to
override subAppend in RollingFileAppender and I'm hoping I don't need to go
through similar pain in 2.

Thanks
Paul

Re: Applying MDC to stacktraces

Posted by Paul Sowden <ps...@gmail.com>.
Did this happen, if so how do I drive it.

Just to clarify:

This is what I have

DEBUG|0222-164903753|main|foo.LogStuff|1fac9d11-484a-4fda-8bbf-fa1b9cb5d73c|bCodeGoesHere|cCodeGoesHere|||hello
world
ERROR|0222-164903753|main|foo.LogStuff|1fac9d11-484a-4fda-8bbf-fa1b9cb5d73c|bCodeGoesHere|cCodeGoesHere|||Something
bad happened
java.lang.Exception: hahahahaha
	at com.foo.LogStuff.logStuff(LogStuff.java:32)
	at com.foo.Startup.main(Startup.java:12)

This is what I want

DEBUG|0222-164903753|main|foo.LogStuff|1fac9d11-484a-4fda-8bbf-fa1b9cb5d73c|bCodeGoesHere|cCodeGoesHere|||hello
world
ERROR|0222-164903753|main|foo.LogStuff|1fac9d11-484a-4fda-8bbf-fa1b9cb5d73c|bCodeGoesHere|cCodeGoesHere|||Something
bad happened
ERROR|0222-164903753|main|foo.LogStuff|1fac9d11-484a-4fda-8bbf-fa1b9cb5d73c|bCodeGoesHere|cCodeGoesHere|||java.lang.Exception:
hahahahaha
ERROR|0222-164903753|main|foo.LogStuff|1fac9d11-484a-4fda-8bbf-fa1b9cb5d73c|bCodeGoesHere|cCodeGoesHere|||	at
com.foo.LogStuff.logStuff(LogStuff.java:32)
ERROR|0222-164903753|main|foo.LogStuff|1fac9d11-484a-4fda-8bbf-fa1b9cb5d73c|bCodeGoesHere|cCodeGoesHere|||	at
com.foo.Startup.main(Startup.java:12)

Thanks

Paul

On Wed, Oct 28, 2015 at 7:11 AM, Ralph Goers <ra...@dslextreme.com>
wrote:

> A couple of new features have been added that should help you:
> 1. Log4j now supports a PatternSelector so you can have multiple patterns
> specified for an appender.
> 2. A new unreleased feature (it will be in 2.5) is the ability to using
> Scripting on the PatternSelector.  With that you can write a script and if
> the LogEvent contains an exception then you would choose the Pattern that
> includes the MDC information.
>
> Ralph


On Wed, Oct 28, 2015 at 10:56 AM, Paul Sowden <ps...@gmail.com> wrote:

> Hi folks,
>
> I'm looking to migrate from log4j1 to 2 and i'm wondering if there's any
> way of making MDC prefixes appear on all stack trace lines. In 1 I had to
> override subAppend in RollingFileAppender and I'm hoping I don't need to go
> through similar pain in 2.
>
> Thanks
> Paul
>

Re: Applying MDC to stacktraces

Posted by Ralph Goers <ra...@dslextreme.com>.
Haven’t even thought about it yet.  Probably a couple of weeks.  I’d like to actually see if I can’t work on a couple of Jira issues this weekend.

Ralph

> On Oct 28, 2015, at 11:52 AM, Gary Gregory <ga...@gmail.com> wrote:
> 
> Curious: When are we thinking WRT 2.5?
> 
> Gary
> 
> On Wed, Oct 28, 2015 at 7:11 AM, Ralph Goers <ralph.goers@dslextreme.com <ma...@dslextreme.com>> wrote:
> A couple of new features have been added that should help you:
> 1. Log4j now supports a PatternSelector so you can have multiple patterns specified for an appender.
> 2. A new unreleased feature (it will be in 2.5) is the ability to using Scripting on the PatternSelector.  With that you can write a script and if the LogEvent contains an exception then you would choose the Pattern that includes the MDC information.
> 
> Ralph
> 
> > On Oct 28, 2015, at 3:56 AM, Paul Sowden <psowden@gmail.com <ma...@gmail.com>> wrote:
> >
> > Hi folks,
> >
> > I'm looking to migrate from log4j1 to 2 and i'm wondering if there's any way of making MDC prefixes appear on all stack trace lines. In 1 I had to override subAppend in RollingFileAppender and I'm hoping I don't need to go through similar pain in 2.
> >
> > Thanks
> > Paul
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org <ma...@logging.apache.org>
> For additional commands, e-mail: log4j-dev-help@logging.apache.org <ma...@logging.apache.org>
> 
> 
> 
> 
> -- 
> E-Mail: garydgregory@gmail.com <ma...@gmail.com> | ggregory@apache.org  <ma...@apache.org>
> Java Persistence with Hibernate, Second Edition <http://www.manning.com/bauer3/>
> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> Spring Batch in Action <http://www.manning.com/templier/>
> Blog: http://garygregory.wordpress.com <http://garygregory.wordpress.com/> 
> Home: http://garygregory.com/ <http://garygregory.com/>
> Tweet! http://twitter.com/GaryGregory <http://twitter.com/GaryGregory>

Re: Applying MDC to stacktraces

Posted by Gary Gregory <ga...@gmail.com>.
Curious: When are we thinking WRT 2.5?

Gary

On Wed, Oct 28, 2015 at 7:11 AM, Ralph Goers <ra...@dslextreme.com>
wrote:

> A couple of new features have been added that should help you:
> 1. Log4j now supports a PatternSelector so you can have multiple patterns
> specified for an appender.
> 2. A new unreleased feature (it will be in 2.5) is the ability to using
> Scripting on the PatternSelector.  With that you can write a script and if
> the LogEvent contains an exception then you would choose the Pattern that
> includes the MDC information.
>
> Ralph
>
> > On Oct 28, 2015, at 3:56 AM, Paul Sowden <ps...@gmail.com> wrote:
> >
> > Hi folks,
> >
> > I'm looking to migrate from log4j1 to 2 and i'm wondering if there's any
> way of making MDC prefixes appear on all stack trace lines. In 1 I had to
> override subAppend in RollingFileAppender and I'm hoping I don't need to go
> through similar pain in 2.
> >
> > Thanks
> > Paul
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-dev-help@logging.apache.org
>
>


-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Re: Applying MDC to stacktraces

Posted by Ralph Goers <ra...@dslextreme.com>.
A couple of new features have been added that should help you:
1. Log4j now supports a PatternSelector so you can have multiple patterns specified for an appender.
2. A new unreleased feature (it will be in 2.5) is the ability to using Scripting on the PatternSelector.  With that you can write a script and if the LogEvent contains an exception then you would choose the Pattern that includes the MDC information.

Ralph

> On Oct 28, 2015, at 3:56 AM, Paul Sowden <ps...@gmail.com> wrote:
> 
> Hi folks,
> 
> I'm looking to migrate from log4j1 to 2 and i'm wondering if there's any way of making MDC prefixes appear on all stack trace lines. In 1 I had to override subAppend in RollingFileAppender and I'm hoping I don't need to go through similar pain in 2.
> 
> Thanks
> Paul



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