Bug 51122 - Include option in throwable pattern converter to control stack trace separator
Summary: Include option in throwable pattern converter to control stack trace separator
Alias: None
Product: Log4j - Now in Jira
Classification: Unclassified
Component: Layout (show other bugs)
Version: 1.2
Hardware: All All
: P2 enhancement
Target Milestone: 1.2.19
Assignee: log4j-dev
Depends on:
Reported: 2011-04-26 14:48 UTC by jpolsky
Modified: 2013-04-10 04:36 UTC (History)
1 user (show)

Proposed Patch (7.69 KB, patch)
2013-02-06 19:38 UTC, jpolsky
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description jpolsky 2011-04-26 14:48:20 UTC
We have software which scans our log files for errors/warns and sends the appropriate alerts to our on-call team.  It would be convenient if we could control the stack trace separator when the exception is logged.

I initial wrote our own custom PatternParser/PatternConverter from the core log4j code base, which used a %S{ | } pattern field, however, since there is already an EnhancedPatternParser in a companion class which has a %throwable specific pattern field, which is exactly what I was trying to accomplish, it seems like it makes more sense to extend that class rather than maintain our own.

The change would be to include an additional (optional) option to ThrowableInformationPatternConverter which sets the trace separator rather than use a hard coded new line, where new line would be the default if not specified.


The pattern could then be extended like the following:

%throwable{full}{ | }

It appears that the code will already provide additional options to the pattern converter constructor if they are chained together.  For this to work, however, the second option would always have to be the stack trace separator, unless there is a way to prefix an option to identify it as the stack trace separator.

Since the idea of the pattern is to have greater control on statement logging, it seems like the responsibility to control the stack trace separator should also live within this class.
Comment 1 jpolsky 2013-02-06 19:38:07 UTC
Created attachment 29930 [details]
Proposed Patch
Comment 2 jpolsky 2013-02-06 19:38:44 UTC
I realize this feature request is quite old and all active development is focused on 2.0.  I've copied this to Log4j2 JIRA and posted a patch there as well:

I'm wondering if there are any plans to build any updates for 1.2; its use at our company is pretty wide spread and any transition to 2.0 wouldn't actually begin until that product is out of beta.

I've ported that same improvement over to the 1.2 code base and attached the proposed patch.

The change would allow the previously hard coded line separator ("\n") to be configurable using the syntax:
Comment 3 grobmeier 2013-04-10 04:36:46 UTC
Thank you for your patch.

We still plan to update 1.2.x series until 2.x is more stable. That said, it highly depends on my own time so far and I am a bit of a bottleneck. My plan is to prepare a release soon, maybe may or so.