2016-03-25 11 views
1

すべてのLog4J 2ロガーをIMAP Disruptorと非同期にしようとしています。私は混乱の依存関係が正しく設定されており、IntelliJではVMオプションの下で次のシステムプロパティを設定しています。Log4J 2非同期ロガーとスレッド

-DLog4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector 

私のlog4j2.xmlファイルはこれです。

私のロガークラスにはこのコードがあります。

package guru.springframework.blog.log4j2async; 

import org.apache.logging.log4j.LogManager; 
import org.apache.logging.log4j.Logger; 

public class Log4J2AsyncLogger { 

private static Logger logger = LogManager.getLogger(); 
public Log4J2AsyncLogger(){ 
    logger.info("Logger created by Thread Id:"+Thread.currentThread().getId()); 
} 
public void performSomeTask(){ 
     logger.debug("This is a debug message sent by Thread Id:" + Thread.currentThread().getId()); 
     logger.info("This is a info message sent by Thread Id:" + Thread.currentThread().getId()); 
     logger.warn("This is a warn message sent by Thread Id:" + Thread.currentThread().getId()); 
     logger.error("This is a error message sent by Thread Id:" + Thread.currentThread().getId()); 
     logger.fatal("This is a fatal message sent by Thread Id:" + Thread.currentThread().getId()); 
} 
} 

私は、異なるスレッドIDを持つログメッセージの出力を期待していました。しかし、コンソールとファイル出力の両方があります:ロガークラスで

[INFO ] 2016-03-25 11:41:01.189 [main] Log4J2AsyncLogger - System property Log4jContextSelector: org.apache.logging.log4j.core.async.AsyncLoggerContextSelector 
[INFO ] 2016-03-25 11:41:01.189 [main] Log4J2AsyncLogger - Logger created by Thread Id:1 
[DEBUG] 2016-03-25 11:41:01.189 [main] Log4J2AsyncLogger - This is a debug message sent by Thread Id:1 
[INFO ] 2016-03-25 11:41:01.189 [main] Log4J2AsyncLogger - This is a info message sent by Thread Id:1 
[WARN ] 2016-03-25 11:41:01.189 [main] Log4J2AsyncLogger - This is a warn message sent by Thread Id:1 
[ERROR] 2016-03-25 11:41:01.189 [main] Log4J2AsyncLogger - This is a error message sent by Thread Id:1 
[FATAL] 2016-03-25 11:41:01.189 [main] Log4J2AsyncLogger - This is a fatal message sent by Thread Id:1 

は、私がメッセージを記録するために1000のループとforループを使用してみましたが、それでも同じメインスレッドがすべての作業を行っています。私は間違って何をしていますか?

答えて

3

Log4jは、呼び出しスレッド(アプリケーションスレッド)にメッセージのスナップショットを作成します。別のバックグラウンドスレッドでディスクに書き込まれますが、メッセージの内容には影響しません。

バックグラウンドスレッドのスレッド名またはIDは、決してログに表示されません。これは設計によるものです。

関連する問題