[ 
https://issues.apache.org/jira/browse/LOG4J2-3034?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17293227#comment-17293227
 ] 

Ralph Goers commented on LOG4J2-3034:
-------------------------------------

Yeah - you want the PatternSelector.


{code:java}
<Configuration status="WARN" name="XMLConfig">
  <Appenders>
    <Console name="STDOUT">
      <PatternLayout>
        <LevelPatternSelector defaultPattern="[%-5level] %c{1.} %msg%n">
          <PatternMatch key="DEBUG" pattern="[%-5level] %c{1.} ====== 
%C{1.}.%M:%L %X %msg ======%n"/>
          <PatternMatch key="TRACE" pattern="[%-5level] %c{1.} ====== 
%C{1.}.%M:%L %X %msg ======%n"/>
        </MarkerPatternSelector>
      </PatternLayout>
    </Console>
  </Appenders>
  <Loggers>
    <Root level="debug">
      <AppenderRef ref="STDOUT" />
    </Root>
  </Loggers>
</Configuration>
{code}
This should output without the classname, method name, line number and MDC for 
everything except DEBUG and TRACE messages, which would include them. The 
[doc|http://logging.apache.org/log4j/2.x/manual/layouts.html#Pattern_Selectors] 
shows other examples. If you use a ScriptPatternSelector then your script just 
returns the key of the pattern you want to use or null to use the default.

> Change Log format based on currently active level
> -------------------------------------------------
>
>                 Key: LOG4J2-3034
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-3034
>             Project: Log4j 2
>          Issue Type: New Feature
>            Reporter: Caleb Cushing
>            Priority: Major
>
> I'm not talking about `patternSelector`, I thought that was what I wanted, 
> but I didn't understand it, I think. What I'm talking about is, if my root 
> current active level is, for example,  `error`, I want a format without MDC, 
> if it's `debug` I want a format with MDC. meaning in error level, and all 
> levels I would want the MDC when my lowest level is `debug` or trace. If it's 
> higher than debug I want no MDC in my output. Pretty sure this is relatively 
> easy to achieve with a programmatic configuration, but not without. The use 
> case is to get far more verbose logging when debugging as opposed to normal 
> "production" mode.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to