Ich versuche, alle Log4J 2 Logger asynchron mit IMAP Disruptor zu machen. Ich habe die Disruptor-Abhängigkeiten korrekt festgelegt, und in IntelliJ habe ich die folgende Systemeigenschaft unter VM-Optionen festgelegt.Log4J 2 Async Logger und Threads
-DLog4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector
Meine log4j2.xml-Datei ist dies.
Meine Logger-Klasse hat diesen Code.
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());
}
}
Ich erwartete die Ausgabe von Protokollnachrichten mit unterschiedlichen Thread-IDs. Aber sowohl die Konsole und Dateiausgaben sind:
[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
In der Logger-Klasse habe ich versucht, einen mit 1000 Loops for-Schleife mit den Nachrichten zu protokollieren, aber immer noch der gleiche Haupt-Thread tut der ganze Arbeit. Was mache ich falsch?