與 log4j2用asyncRoot配置異步日誌是如何使用disruptor差別有幾個:java
此處EventFactory採用的是RingBufferLogEvent.FACTORY,newInstance邏輯大體是:異步
public RingBufferLogEvent newInstance() { final RingBufferLogEvent result = new RingBufferLogEvent(); if (Constants.ENABLE_THREADLOCALS) { result.messageText = new StringBuilder(Constants.INITIAL_REUSABLE_MESSAGE_SIZE); result.parameters = new Object[10]; } return result; }
建立的是 RingBufferLogEvent
實例。該對象封裝了日誌輸出的執行動做等。async
thread factory的名字是"AsyncLogger[" + contextName + "]"ui
此處用RingBufferLogEventHandler,對接RingBufferLogEvent實例處理日誌寫出。日誌
此處用RingBufferLogEventTranslator,對接RingBufferLogEvent實例組裝日誌信息。code
封裝了一個叫tryPublish的方法進入隊列。對象