Log4j2 and Kafka Integration

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.