kafka 源碼 debug環境搭建

添加啓動項。Edit Configurations->點擊+號->Application添加一個啓動項,而後填寫以下內容html


編輯啓動項

在build.gradle中添加以下內容,其中2.12.0改成你使用的對應版本便可git

dependencies {
    compile 'org.scala-lang:scala-library:2.12.0'
}

解決報錯

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder"github

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

build.gradle的子項目core中須要添加這兩個依賴:apache

project(':core') {
  println "Building project 'core' with Scala version ${versions.scala}"
  ...

  dependencies {
    ...
    // 添加如下兩個依賴
    // https://mvnrepository.com/artifact/org.slf4j/slf4j-api
    compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
    // https://mvnrepository.com/artifact/org.slf4j/slf4j-log4j12
    compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.25'
}

這兩行首先要添加slf4j的依賴,還要添加基於slf4j的log4j12的依賴。注意這裏必定要用compile而不是testCompile,由於後者的意思是隻在test環境下編譯.api

我當時就是由於直接從Maven官網上拷貝了以下內容翻了車:ruby

testCompile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.25'  // 不要這樣寫

log4j:WARN No appenders could be found for logger (LoggerMain).bash

log4j:WARN No appenders could be found for logger (LoggerMain).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

建立src/main/resources文件夾,建立文件log4j.properties,並寫入如下內容:app

### 設置###
log4j.rootLogger = debug,stdout

### 輸出信息到控制擡 ###
log4j.appender.stdout = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target = System.out
log4j.appender.stdout.Threshold = INFO
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern = [%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n

其它踩坑ide

本文同步分享在 博客「不存在的裏皮」(JianShu)。
若有侵權,請聯繫 support@oschina.cn 刪除。
本文參與「OSC源創計劃」,歡迎正在閱讀的你也加入,一塊兒分享。svg

相關文章
相關標籤/搜索