You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "wangbaohua (Jira)" <ji...@apache.org> on 2021/12/21 08:41:00 UTC

[jira] [Created] (LOG4J2-3266) ${CTX :ThreadName} does not work

wangbaohua created LOG4J2-3266:
----------------------------------

             Summary: ${CTX :ThreadName} does not work  
                 Key: LOG4J2-3266
                 URL: https://issues.apache.org/jira/browse/LOG4J2-3266
             Project: Log4j 2
          Issue Type: Bug
          Components: API
    Affects Versions: 2.17.0
            Reporter: wangbaohua


${CTX :ThreadName} does not work at 2.17.0, but works fine below 2.16.0  

My configuration is as follows  :

---------------------------------------------------------------------------------------------------

<?xml version="1.0" encoding="utf-8"?>
<!--按线程分文件,按线程ID:ThreadID 按线程名:ThreadName-->
<!--monitorInterval 热改生效时长配置 值以分钟为单位-->
<configuration monitorInterval="1">
  <!--属性定义-->
  <Properties>
    <!-- 日志路径 -->
    <property name="LOG_HOME">${sys:logPath}</property>
    <!--日志切割的最小单位-->
    <property name="every_file_size">50M</property>
    <!--日志打印格式-->
    <property name="log_pattern">%d\{yyyy-MM-dd HH:mm:ss,SSS} %-5.5p [%t] %X\{codeline} -%m%n</property>
    <!--日志输出级别-->
    <property name="output_log_level_fatal">fatal</property>
    <property name="output_log_level_warn">warn</property>
    <property name="output_log_level_debug">debug</property>
    <property name="output_log_level_info">info</property>
    <property name="output_log_level_error">error</property>
    <property name="output_log_level_trace">trace</property>
    <!--打印模式:线程打印(thread),汇总打印(summary)-->
    <property name="print_type">summary</property>
    <property name="max_size">10</property>
    <property name="error_file">${LOG_HOME}/logs/log.error</property>
    <property name="Thread_file">${LOG_HOME}/logs/log.${ctx:ThreadName}</property>
    <property name="all_file">${LOG_HOME}/logs/DLframe.log</property>
    <property name="kafka_file">${LOG_HOME}/logs/log.kafka</property>
  </Properties>
  <Appenders>
    <Kafka name="Kafka" topic="dlFrameAlarm">
      <Property name="bootstrap.servers">KAFKA0:9092</Property>
      <PatternLayout>
        <pattern>\{"time":"%d{yyyy-MM-dd HH:mm:ss}","App":"alarmEngine","hostName":"${env:HOSTNAME}","loggerName":"%c","line":"%L","level":"%p","thread":"%t","message":"%m"}
        </pattern>
      </PatternLayout>

      <Filters>
        <ThresholdFilter level="warn" onMatch="ACCEPT" onMismatch="DENY"/>
      </Filters>
    </Kafka>
    <!--ERROR日志输出,包括(FATAL ERROR Exception)-->
    <RollingFile name="errorRolling" fileName="${error_file}" filePattern="${LOG_HOME}/logs/log.error.%i">
      <PatternLayout pattern="${log_pattern}"/>
      <SizeBasedTriggeringPolicy size="${every_file_size}"/>           
      <DefaultRolloverStrategy max="${max_size}"/>
      <Filters>
        <!--RegexFilter regex=".*Exception.*" onMatch="ACCEPT" onMismatch="NEUTRAL"/-->
        <ThresholdFilter level="error" onMatch="ACCEPT" onMismatch="DENY"/>
      </Filters>
    </RollingFile>

    <!--日志输出,按线程名称进行-->
    <Routing name="ThreadRolling">
      <Routes pattern="$${ctx:ThreadName}">
        <Route>
          <RollingFile name="RollingFile-${ctx:ThreadName}" fileName="${Thread_file}" filePattern="${LOG_HOME}/logs/log.${ctx:ThreadName}.%i" append="true">
            <PatternLayout pattern="${log_pattern}"/>
            <Policies>
              <SizeBasedTriggeringPolicy size="${every_file_size}"/>
            </Policies>
            <DefaultRolloverStrategy max="${max_size}"/>
            <Filters>
              <ThresholdFilter level="fatal" onMatch="ACCEPT" onMismatch="NEUTRAL"/>
              <ThresholdFilter level="error" onMatch="ACCEPT" onMismatch="NEUTRAL"/>
              <ThresholdFilter level="warn" onMatch="ACCEPT" onMismatch="NEUTRAL"/>
              <ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="NEUTRAL"/>
              <ThresholdFilter level="debug" onMatch="ACCEPT" onMismatch="NEUTRAL"/>
              <ThresholdFilter level="trace" onMatch="ACCEPT" onMismatch="DENY"/>
            </Filters>
          </RollingFile>
        </Route>
      </Routes>
    </Routing>
    <!-- =======================================打印汇总的日志到文件======================================= -->
    <RollingFile name="allRolling" fileName="${all_file}" filePattern="${LOG_HOME}/logs/DLframe.log.%i" append="true">
      <PatternLayout pattern="${log_pattern}"/>
      <Policies>
        <SizeBasedTriggeringPolicy size="${every_file_size}"/>
      </Policies>
      <DefaultRolloverStrategy max="${max_size}" />
      <Filters>
        <ThresholdFilter level="fatal" onMatch="ACCEPT" onMismatch="NEUTRAL"/>
        <ThresholdFilter level="error" onMatch="ACCEPT" onMismatch="NEUTRAL"/>
        <ThresholdFilter level="warn" onMatch="ACCEPT" onMismatch="NEUTRAL"/>
        <ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="NEUTRAL"/>
        <ThresholdFilter level="debug" onMatch="ACCEPT" onMismatch="NEUTRAL"/>
        <ThresholdFilter level="trace" onMatch="ACCEPT" onMismatch="DENY"/>
      </Filters>
    </RollingFile>
    <!-- =======================================打印kafka的日志到文件======================================= -->
    <RollingFile name="kafkaFile" fileName="${kafka_file}" filePattern="${LOG_HOME}/logs/log.kafka.%i" append="true">
      <PatternLayout pattern="${log_pattern}"/>
      <Policies>
        <SizeBasedTriggeringPolicy size="${every_file_size}"/>
      </Policies>
      <DefaultRolloverStrategy max="${max_size}" />
      <Filters>
        <ThresholdFilter level="fatal" onMatch="ACCEPT" onMismatch="NEUTRAL"/>
        <ThresholdFilter level="error" onMatch="ACCEPT" onMismatch="NEUTRAL"/>
        <ThresholdFilter level="warn" onMatch="ACCEPT" onMismatch="NEUTRAL"/>
        <ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="NEUTRAL"/>
        <ThresholdFilter level="debug" onMatch="ACCEPT" onMismatch="NEUTRAL"/>
        <ThresholdFilter level="trace" onMatch="ACCEPT" onMismatch="DENY"/>
      </Filters>
    </RollingFile>
  </Appenders>
  <Loggers>
    <!--业务、平台侧的日志都打在一起,这样便于定位问题-->
    <Logger name="com.asap" level="${output_log_level_info}" includeLocation="true">
      <AppenderRef ref="ThreadRolling"/>
      <AppenderRef ref="errorRolling"/>
      <AppenderRef ref="Kafka"/>
    </Logger>
    <!--业务、平台侧的日志都打在一起,这样便于定位问题-->
    <Logger name="org.apache.kafka" level="${output_log_level_warn}" includeLocation="true">
      <AppenderRef ref="kafkaFile"/>
    </Logger>
    <!--必须配置root信息-->
    <Root level="${output_log_level_error}" includeLocation="false"/>
  </Loggers>
</configuration>

-------------------------------------------------------------------------------------------------



--
This message was sent by Atlassian Jira
(v8.20.1#820001)