DropWizard无需使用LogBack并支持我的log4j.properties [英] DropWizard without using LogBack and support for my log4j.properties

查看:206
本文介绍了DropWizard无需使用LogBack并支持我的log4j.properties的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

kafka源连接器在我的代码中使用Dropwizard进行指标注册.我启用了自定义端口以在浏览器中查看. 最初,在连接器中没有dropwizard时,我使用log4j.properties进行日志记录(slf4j). 当我在连接器中自动使用dropwizard时,它将切换到logback并显示以下结果:

kafka source Connector uses Dropwizard for metrics registration in my code. I enabled custom port to see in my browser. Initially without dropwizard in connector, I used log4j.properties for logging( slf4j). When i used dropwizard in connector automatically it switches to logback and showing the folowing results:

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文件以运行服务器

conf.yml file for dropwizard to run server

server:
  adminConnectors:
  - type: http
    port: 8989

代码段

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

When i run the code automatically goes into debug mode and not using my custom log4j.properties. Some of dependecies added in my 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日志记录级别的依赖项时,代码将引发异常:

When i excluded dependecnies of all dropwizard logback logging levels from io.dropwizard-core then the code raising an exception:

 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 无法从dropwizard项目中排除经典的logback依赖项 点:我将myconnector jar复制到kafka libs(因为kafka需要识别myconnecotr jar),以便如果我运行任何其他kafkaDependecy编程jar,则programm进入调试模式并显示以上警告多个slf4j绑定并绑定到ch.qos.logback .

below links which they are suggedted are tired in my code https://github.com/dropwizard/dropwizard/pull/2112 https://github.com/dropwizard/dropwizard/pull/1900 Can't exclude logback-classic dependency from dropwizard project Point: I copied myconnector jar to kafka libs(Because kafka needs to identify myconnecotr jar) so that If i run any other kafka dependecy programming jars then programm goes into debug mode and showing above warnings Multiple slf4j bindings and binding to ch.qos.logback.

推荐答案

我试图在稍有不同的情况下解决基本相同的问题,并在此处遇到关键信息: https://www.dropwizard.io/1.3.5/docs/manual/core.html#logging .我已经在排除logging jar,并根据在其他地方找到的信息来覆盖bootstrapLogging方法,但是我缺少的部分(在config.yml文件中)是:

I was trying to solve basically the same problem in a slightly different context and ran across key info here: https://www.dropwizard.io/1.3.5/docs/manual/core.html#logging. I was already excluding the logback jars and overriding the bootstrapLogging method based on information found elsewhere, but the part I was missing (in the config.yml file) was:

server:
  type: simple
  applicationContextPath: /application
  adminContextPath: /admin
  requestLog:
    type: external
logging:
  type: external

我是在几分钟前才发现的,所以这就是我目前所知道的. (不知道上面的每一点是否都是必要的,或者它到底是做什么的.)但是,它确实让我使用了log4j,而没有尝试使用logback的代码抛出异常.

I just found this minutes ago, so that's as much as I know at the moment. (Not sure if every bit of the above is necessary, nor exactly what it does.) But it did let me use log4j without exceptions being thrown from code trying to use logback.

我发现> https://github.com/dropwizard中已经存在相同的信息/dropwizard/pull/1900 在OP中引用,但当时尚未正式发布.

I discovered the same info is already in https://github.com/dropwizard/dropwizard/pull/1900 referenced in the OP, but was not official at that time.

这篇关于DropWizard无需使用LogBack并支持我的log4j.properties的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆