• Kafka源码工程examples项目配置log4j


    examples项目启动想知道有哪些错误,通过日志了解代码执行逻辑,但是启动SimpleConsumerDemo了报错如下:

    log4j.proproties也配置了

    log4j.proproties配置如下:

    # Licensed to the Apache Software Foundation (ASF) under one or more
    # contributor license agreements.  See the NOTICE file distributed with
    # this work for additional information regarding copyright ownership.
    # The ASF licenses this file to You under the Apache License, Version 2.0
    # (the "License"); you may not use this file except in compliance with
    # the License.  You may obtain a copy of the License at
    #
    #    http://www.apache.org/licenses/LICENSE-2.0
    #
    # Unless required by applicable law or agreed to in writing, software
    # distributed under the License is distributed on an "AS IS" BASIS,
    # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    # See the License for the specific language governing permissions and
    # limitations under the License.
    log4j.rootLogger=DEBUG, stdout, log
    
    log4j.appender.stdout=org.apache.log4j.ConsoleAppender
    log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
    log4j.appender.stdout.layout.ConversionPattern=[%d] %p %m (%c:%L)%n
    
    log4j.logger.kafka=DEBUG
    log4j.logger.org.apache.kafka=DEBUG
    
    ### log file ###
    log4j.appender.log = org.apache.log4j.DailyRollingFileAppender
    log4j.appender.log.File = /Users/lizhitao/code/kafka-0.11.0.2-src/examples/logs/kafka.log
    log4j.appender.log.Append = true
    log4j.appender.log.Threshold = DEBUG
    log4j.appender.log.DatePattern='.'yyyy-MM-dd
    log4j.appender.log.layout = org.apache.log4j.PatternLayout
    log4j.appender.log.layout.ConversionPattern = [kafka][%p] [%-d{yyyy-MM-dd HH:mm:ss}] %C.%M(%L) | %m%n
    
    
    # zkclient can be verbose, during debugging it is common to adjust is separately
    log4j.logger.org.I0Itec.zkclient.ZkClient=WARN
    log4j.logger.org.apache.zookeeper=WARN
     

    No appenders could be found for logger,意思是log4.proproties找不到,如果默认位置找不到,我们可以自行动态配置

    generateData()方法加入如下log4j配置代码:

    PropertyConfigurator.configure("/Users/lizhitao/code/xxx-proj/kafka-0.11.0.2-src/examples/src/main/resources/log4j.properties");

    再次启动SimpleConsumerDemo,搞定,日志有输出

  • 相关阅读:
    2020-03-23
    2020-03-22
    2020-03-21
    2020-03-20
    2020-03-19
    2020-03-18
    2020-03-17
    单元测试-java
    2020-03-16
    C语言拯救计划Day3-1之求一批整数中出现最多的个位数字
  • 原文地址:https://www.cnblogs.com/lizherui/p/8973618.html
Copyright © 2020-2023  润新知