logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From רפי <rafr...@gmail.com>
Subject Log4j2 - replace some text with other log4j2 conversion pattern (with %level for example)‏
Date Mon, 12 Oct 2020 09:56:35 GMT
In log4j2 configured by log4j2.xml - how can I replace some text with
other conversion
pattern?


For example, I have some message with the word "LOGLEVEL" and I want to
replace it with the current log level (WARN/DEBUG/ERROR/TRACE/INFO). The
conversion pattern
<https://logging.apache.org/log4j/2.x/manual/layouts.html> for the log
level is %p or %level, so I tried this:

%replace{%msg}{LOGLEVEL}{%level}

But instead of replacing the "LOGLEVEL" text with the actual *level* it
just replaced it with the text "%level".

*The original message was*: this trace is LOGLEVEL log

*For INFO trace I want to get*: this trace is INFO log

*But I actually got*: this trace is %level log

How can I achieve this requirement?



I asked it on StackOverflow but no one knows the answer.

https://stackoverflow.com/questions/64305649/log4j2-replace-some-text-with-other-log4j2-conversion-pattern-with-level-for



Thanks,

Refael

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message