You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Yogi Nerella <yn...@gmail.com> on 2013/02/15 21:02:48 UTC
Can substitution in replace regexpression take the MDC context key name?
Hi,
I want to replace some constant strings with the MDC.context() values?
Does regularexpress replace support this?
Ex:
%replace{%msg}{myappname}{%X{appname}}
Thanks
Yogi
Re: Can substitution in replace regexpression take the MDC context
key name?
Posted by Yogi Nerella <yn...@gmail.com>.
Ralph,
My intention is basically to replace all "\n" in the message with the
ThreadContext for our application.
I think RegexReplacement is not taking variables for pattern and
substitution.
I am using the following in pattern-layout, but the substitution is not
happening correctly, and also by looking at the code, it looks like code do
not support.
<PatternLayout>
<pattern>%-5p | %X | %d{MM-dd-yyyy HH:mm} |%10sn |
%replace{%msg}{\n}{%%X{host}}%n</pattern>
RegexReplacement class do not have any information about the context, so
it cannot resolve %X{host} for substitution string.
public String format(final String msg) {
return pattern.matcher(msg).replaceAll(substitution);
}
this could be as follows
public String format(final String msg, String paramSubstitution)
{
// substitution should be formatted with the formatter, and then
passed to this method.
return pattern.matcher(msg).replaceAll(paramSubstitution);
}
Yogi
On Fri, Feb 15, 2013 at 4:04 PM, Ralph Goers <ra...@dslextreme.com>wrote:
> Where are you wanting to do this? In a pattern in the pattern layout you
> just use %X{app name} as you show below. In many places you can use
> ${mdc:name}.
>
> Ralph
>
>
> On Feb 15, 2013, at 12:02 PM, Yogi Nerella wrote:
>
> > Hi,
> >
> > I want to replace some constant strings with the MDC.context() values?
> >
> > Does regularexpress replace support this?
> >
> > Ex:
> > %replace{%msg}{myappname}{%X{appname}}
> >
> > Thanks
> > Yogi
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>
Re: Can substitution in replace regexpression take the MDC context key name?
Posted by Ralph Goers <ra...@dslextreme.com>.
Where are you wanting to do this? In a pattern in the pattern layout you just use %X{app name} as you show below. In many places you can use ${mdc:name}.
Ralph
On Feb 15, 2013, at 12:02 PM, Yogi Nerella wrote:
> Hi,
>
> I want to replace some constant strings with the MDC.context() values?
>
> Does regularexpress replace support this?
>
> Ex:
> %replace{%msg}{myappname}{%X{appname}}
>
> Thanks
> Yogi
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org