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 bu...@apache.org on 2007/09/16 20:34:03 UTC

DO NOT REPLY [Bug 43403] - PatternLayout: new format modifer: prefix if non-empty

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=43403>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=43403





------- Additional Comments From carnold@apache.org  2007-09-16 11:34 -------
I think the use case is reasonable, but I don't think the proposed solution is desirable.  First, the 
proposed solution isn't general enough. if there is a "prefix" why shouldn't there be a "suffix" too.  If it 
is desirable for NDC and MDC, why not for other fields as well. Second, implementing the solution 
would require hacking the pattern parser to support a new language feature.

ExtendedPatternLayout (the log4j 1.3 pattern layout backported for use with log4j 1.2 and provided in 
the extras companion) does support just %X which will print out all MDC values as key=value.

XSLTLayout (also in the extras) companion should also be capable of achieving your desired layout 
goals.  I haven't benchmarked XSLTLayout, but I would assume that it would have to be substantially 
slower than PatternLayout for equivalent tasks.  But it is hugely flexible and the performance different 
may not be an issue in your application.

If that isn't desirable, then possibly adding a new "replace" pattern to ExtendedPatternLayout in apache-
log4j-extras would be a reasonable approach that would not require hacking the pattern parser, just 
adding a new pattern specifier.  replace could look like:

%replace{layout pattern}{regex}{replacement}

So your NDC prefix would look like:

%c%replace{%x}{(.+)}{-$1}



-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

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