【发布时间】:2018-09-23 23:07:37
【问题描述】:
kafka source Connector 在我的代码中使用 Dropwizard 进行指标注册。我启用了自定义端口以在我的浏览器中查看。 最初在连接器中没有 dropwizard,我使用 log4j.properties 进行日志记录(slf4j)。 当我在连接器中使用 dropwizard 时,它会自动切换到 logback 并显示以下结果:
SLF4J: Found binding in [jar:file:jarfilename/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/kafka_2.12-0.10.2.1/libs/slf4j-log4j12-1.7.21.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
Apr 13, 2018 8:58:47 AM org.glassfish.jersey.internal.Errors logErrors
WARNING: The following warnings have been detected: WARNING: The (sub)resource method createConnector in org.apache.kafka.connect.runtime.rest.resources.ConnectorsResource contains empty path annotation.
WARNING: The (sub)resource method listConnectors in org.apache.kafka.connect.runtime.rest.resources.ConnectorsResource contains empty path annotation.
WARNING: The (sub)resource method listConnectorPlugins in org.apache.kafka.connect.runtime.rest.resources.ConnectorPluginsResource contains empty path annotation.
WARNING: The (sub)resource method serverInfo in org.apache.kafka.connect.runtime.rest.resources.RootResource contains empty path annotation.
用于 dropwizard 运行服务器的 conf.yml 文件
server:
adminConnectors:
- type: http
port: 8989
代码sn-p
public class KafkaMetricsPort extends Application<MetricsConfiguration>{
@Override
public void run(MetricsConfiguration configuration, Environment environment) throws Exception {
}
}
import io.dropwizard.Configuration;
public class MetricsConfiguration extends Configuration{
}
当我运行代码时会自动进入调试模式,而不是使用我的自定义 log4j.properties。 我的 pom.xml 中添加了一些依赖项
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-core</artifactId>
<version>0.9.2</version>
<dependency>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-core</artifactId>
<version>3.1.2</version>
当我从 io.dropwizard-core 中排除所有 dropwizard logback 日志记录级别的依赖项时,代码会引发异常:
Caused by: java.lang.ClassNotFoundException:
ch.qos.logback.classic.filter.ThresholdFilter
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
他们建议的链接在我的代码中很累 https://github.com/dropwizard/dropwizard/pull/2112 https://github.com/dropwizard/dropwizard/pull/1900 Can't exclude logback-classic dependency from dropwizard project 要点:我将 myconnector jar 复制到 kafka libs(因为 kafka 需要识别 myconnecotr jar),这样如果我运行任何其他 kafka 依赖编程 jar,则程序会进入调试模式并显示上述警告 Multiple slf4j bindings and binding to ch.qos.logback .
【问题讨论】:
标签: java logging logback slf4j dropwizard