0

我正在为我的 logback xml 使用以下配置:

    <appender name="LOKI" class="com.github.loki4j.logback.Loki4jAppender">
        <http class="com.github.loki4j.logback.ApacheHttpSender">
             <url>${LOKI_ENDPOINT_URL}</url>
        </http>
         <batchMaxItems>${LOKI_BATCH_SIZE}</batchMaxItems>
         <batchTimeoutMs>${LOKI_BATCH_TIMEOUT_MS}</batchTimeoutMs>
         <format>
             <label>
                 <pattern>${LOKI_LABEL_PATTERN}</pattern>
             </label>
             <message>
                 <pattern>${LOKI_MSG_PATTERN}</pattern>
             </message>
             <sortByTime>true</sortByTime>
         </format>
      </appender>

在定义 Loki appender 之后,我想在已经存在的记录器中有条件地使用它:

     <logger name="com.model.inf" level="INFO" additivity="true">
        <appender-ref ref="EXISTING-APPENDER"/>
        <if condition='property("LOKI_SERVICE_URL").length() > 0'>
           <then>
              <appender-ref ref="LOKI"/>
           </then>
         </if>
      </logger>

我现在遇到的问题是,当 if 条件为假时,EXISTING-APPENDER 不会在文件系统上输出任何文件(没有定义 LOKI_SERVICE_URL)

也许我的 logback 配置是错误的,它应该看起来像这样:

    <logger name="com.model.inf" level="INFO" additivity="true">
        <if condition='property("LOKI_SERVICE_URL").length() > 0'>
           <then>
              <appender-ref ref="LOKI"/>
           </then>
         </if>
         <else>
            <appender-ref ref="EXISTING-APPENDER"/>
         </else>
      </logger>

有谁知道这个问题的原因是什么?谢谢!

4

0 回答 0