Class PipelineContextTurboFilter

java.lang.Object
ch.qos.logback.core.spi.ContextAwareBase
ch.qos.logback.classic.turbo.TurboFilter
com.streamconverter.logging.PipelineContextTurboFilter
All Implemented Interfaces:
ch.qos.logback.core.spi.ContextAware, ch.qos.logback.core.spi.LifeCycle

public class PipelineContextTurboFilter extends ch.qos.logback.classic.turbo.TurboFilter
ログ出力直前にPipelineContextの共有値をMDCへ同期するTurboFilter。

パイプライン内のあるコマンドが PipelineContext.putShared(String, String) で設定した値を、 他のコマンドスレッドのログ出力時に自動的にMDCへ反映する。

logback.xmlに以下を追加して有効化する:


 <turboFilter class="com.streamconverter.logging.PipelineContextTurboFilter"/>
 
  • Field Summary

    Fields inherited from class ch.qos.logback.core.spi.ContextAwareBase

    context
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    ch.qos.logback.core.spi.FilterReply
    decide(org.slf4j.Marker marker, ch.qos.logback.classic.Logger logger, ch.qos.logback.classic.Level level, String format, Object[] params, Throwable t)
    ログイベント発生直前に PipelineContext.syncToMDC() を呼び出し、 パイプライン共有値を呼び出しスレッドのMDCへ反映する。

    Methods inherited from class ch.qos.logback.classic.turbo.TurboFilter

    decide, getName, isStarted, setName, start, stop

    Methods inherited from class ch.qos.logback.core.spi.ContextAwareBase

    addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getDeclaredOrigin, getStatusManager, setContext

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • decide

      public ch.qos.logback.core.spi.FilterReply decide(org.slf4j.Marker marker, ch.qos.logback.classic.Logger logger, ch.qos.logback.classic.Level level, String format, Object[] params, Throwable t)
      ログイベント発生直前に PipelineContext.syncToMDC() を呼び出し、 パイプライン共有値を呼び出しスレッドのMDCへ反映する。

      フィルタリングは行わず、常に FilterReply.NEUTRAL を返す。

      このフィルタはログを発生させたスレッドと同一スレッドで実行されるため、 PipelineContext.syncToMDC() によりそのスレッドのMDCのみが更新される。 これは PipelineContextThreadLocal ベースであるための前提条件であり、 TurboFilter の仕様(ログ発生スレッドでの同期実行)により保証されている。

      Specified by:
      decide in class ch.qos.logback.classic.turbo.TurboFilter
      Parameters:
      marker - ログマーカー(未使用)
      logger - ログ出力元ロガー(未使用)
      level - ログレベル(未使用)
      format - メッセージフォーマット(未使用)
      params - メッセージパラメータ(未使用)
      t - 例外(未使用)
      Returns:
      常に FilterReply.NEUTRAL