简体   繁体   English

Dropwizard应用程序不使用来自configuration.yml的日志配置

[英]Dropwizard application not using log config from configuration.yml

I am trying to get DropWizard to log to an output file. 我想让DropWizard登录到输出文件。 The file is being created but nothing written to it. 正在创建文件,但没有写入任何文件。

In fact it would appear that the configuration in the provided .yml file is not being used. 事实上,似乎没有使用提供的.yml文件中的配置。

I am also getting the following warnings during startup, not sure if they are related: 我在启动期间也收到以下警告,不确定它们是否相关:

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/conor/.m2/repository/ch/qos/logback/logback-classic/1.1.3/logback-classic-1.1.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/conor/.m2/repository/com/conor/project/project-common/0.1-SNAPSHOT/project-common-0.1-SNAPSHOT.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.

How can I get dropwizard to pickup the logging config in the yml provided at startup and how can I figure out where the current config is coming from? 如何让dropwizard在启动时提供的yml中获取日志配置,如何确定当前配置的来源? Thanks. 谢谢。

UPDATE:: 更新::

I am running DropWizard v0.9.1 and my logging configuration is as follows: 我正在运行DropWizard v0.9.1 ,我的日志配置如下:

# Logging settings.
logging:

  # The default level of all loggers. Can be OFF, ERROR, WARN, INFO, DEBUG, TRACE, or ALL.
  level: TRACE

  # Logger-specific levels.
  loggers:

#     Sets the level for 'com.example.app' to DEBUG.
    io.dropwizard: INFO

#     Redirects SQL logs to a separate file
    org.hibernate.SQL:
      level: DEBUG

# Logback's Time Based Rolling Policy - archivedLogFilenamePattern: /tmp/application-%d{yyyy-MM-dd}.log.gz
# Logback's Size and Time Based Rolling Policy -  archivedLogFilenamePattern: /tmp/application-%d{yyyy-MM-dd}-%i.log.gz
# Logback's Fixed Window Rolling Policy -  archivedLogFilenamePattern: /tmp/application-%i.log.gz

  appenders:
    - type: console
    - type: file
      threshold: DEBUG
      logFormat: "%-6level [%d{HH:mm:ss.SSS}] [%t] %logger{5} - %X{code} %msg %n"
      currentLogFilename: output/logs/dropwizard.txt
      archivedLogFilenamePattern: output/logs/dropwizard-%d{yyyy-MM-dd}-%i.txt.gz
      archivedFileCount: 10
      timeZone: UTC
      maxFileSize: 10MB

This looks like a typical SLF4J binding issue and is solved easily. 这看起来像是一个典型的SLF4J绑定问题,很容易解决。 First take a look at the relevant section in the URL provided with the warning for an explanation.: 首先看一下提供警告URL中的相关部分,以获得解释:

The warning emitted by SLF4J is just that, a warning. SLF4J发出的警告只是一个警告。 Even when multiple bindings are present, SLF4J will pick one logging framework/implementation and bind with it . 即使存在多个绑定, SLF4J也会选择一个日志框架/实现并与之绑定 The way SLF4J picks a binding is determined by the JVM and for all practical purposes should be considered random . SLF4J选择绑定的方式由JVM确定,并且出于所有实际目的应该被认为是随机的 As of version 1.6.6, SLF4J will name the framework/implementation class it is actually bound to. 从版本1.6.6开始,SLF4J将命名它实际绑定的框架/实现类。 Embedded components such as libraries or frameworks should not declare a dependency on any SLF4J binding but only depend on slf4j-api. 嵌入式组件(如库或框架)不应声明对任何SLF4J绑定的依赖性,而仅依赖于slf4j-api。 When a library declares a compile-time dependency on a SLF4J binding, it imposes that binding on the end-user, thus negating SLF4J's purpose. 当库声明对SLF4J绑定的编译时依赖性时,它会对最终用户强制绑定,从而否定SLF4J的用途。 When you come across an embedded component declaring a compile-time dependency on any SLF4J binding, please take the time to contact the authors of said component/library and kindly ask them to mend their ways . 当您遇到一个嵌入式组件声明对任何SLF4J绑定的编译时依赖关系时,请花时间联系所述组件/库的作者,并请他们修改他们的方法

Since the binding choice is random, my guess is that the project-common SLF4J dependency is being bound and not the intended one from logback-classic , a transitive dependency of dropwizard . 由于绑定选择是随机的,我的猜测是project-common SLF4J依赖关系是绑定的而不是logback-classic的预期绑定,它是dropwizard的传递依赖。 You should either exclude the one in the project-common in your Maven pom file or better yet, if you have access to the code to project-common , remove it from the pom file as the linked-to web page suggests (ie "mend their ways"). 您应该在Maven pom文件中排除project-common中的那个project-common或者更好,如果您可以访问project-common的代码,将其从pom文件中删除,如链接到网页所示(即“修补”他们的方式“)。

From the Exception, I think you are using the two different version of logback classic both in class path which arise the conflicts. 从Exception中,我认为你在类路径中使用两个不同版本的logback经典产生了冲突。 Try to find out the jar which are included two times but different version and remove one of them. 尝试找出包含两次但不同版本的jar并删除其中一个。 If you are using the Maven to manage the dependency exclude the jar using the tag 如果您使用Maven来管理依赖项,请使用标记排除jar

    <exclusions>
      <exclusion>
       <groupId>ch.qos.logback</groupId>
         <artifactId>logback-classic</artifactId>
         <version>the version you want to remove</version>
     </exclusion>
    </exclusions>  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM