kafka java client 添加log4j日志打印输出到控制台

由于通过kafka java client无法通过ssl+sasl的方式消费数据,为了便于定位问题,希望开启客户端的日志打印。开启方式如下:

1、在maven中添加依赖

        <!--log4j2到slf4j桥梁-->
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-slf4j-impl</artifactId>
            <version>2.9.1</version>
        </dependency>

        <!--log4j2 begin-->
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
            <version>2.11.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>2.11.0</version>
        </dependency>
        <!--log4j2 end-->

2、在resource目录下添加log4j2.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
    <Appenders>
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
        </Console>
    </Appenders>
    <Loggers>
        <Root level="trace">
            <AppenderRef ref="Console"/>
        </Root>
    </Loggers>
</Configuration>

3、重启运行,控制台即出现日志打印

 

posted @ 2021-07-16 09:21  cosmocosmo  阅读(889)  评论(0编辑  收藏  举报