Log4j2 Dependency
<Dependency>
<groupId>org.apache.logging.log4j</groupId>
<Artifactid>Log4j-web</Artifactid>
<version>2.4</version>
<Scope>Runtime</Scope>
</Dependency>
Kafka Dependency
<Dependency>
<groupId>Org.apache.kafka</groupId>
<Artifactid>kafka_2.10</Artifactid>
<version>0.8.2.0</version>
</Dependency>
Log4j2.xml
1<?XML version= "1.0" encoding= "UTF-8"?>
2<ConfigurationStatus= "Warn"name= "MYAPP"Packages="">
3<appenders>
4<Consolename= "STDOUT"Target= "System_out">
5<Patternlayoutpattern= "%d%p%c{1.} [%t]%m%n "/>
6</Console>
7<Kafkaname= "Kafka"Topic= "Log-test">
8<Patternlayoutpattern= "%date%message"/>
9< Propertyname= "Bootstrap.servers">192.168.194.110:9092</ Property>
Ten</Kafka>
One</appenders>
A <Loggers>
-<Root Level= "Trace">
-<Appenderrefref= "STDOUT"/>
the<Appenderrefref= "Kafka"/>
-</Root>
-</Loggers>
-</Configuration>
Main.java
1ImportOrg.apache.logging.log4j.LogManager;
2ImportOrg.apache.logging.log4j.Logger;
3
4 PublicclassMain {
5PrivateStaticFinalLogger Logger = Logmanager.getlogger (Main.class);
6
7 Public StaticvoidMain (string[] args) {
8Logger.info ("Hello log4j!!!");
9}
Ten
One}
A
Console:
Kafka Client
Log4j2 and Kafka Integration