我正在尝试让 DropWizard 记录到一个输出文件。正在创建文件,但没有写入任何内容。
事实上,提供的 .yml 文件中的配置似乎没有被使用。
我在启动过程中也收到以下警告,不确定它们是否相关:
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.
如何让 dropwizard 在启动时提供的 yml 中获取日志配置,以及如何找出当前配置的来源?谢谢。
更新::
我正在运行 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
最佳答案
这看起来像一个典型的 SLF4J
绑定(bind)问题,很容易解决。先看看URL provided with the warning中的相关部分以获得解释。:
The warning emitted by SLF4J is just that, a warning. Even when multiple bindings are present, SLF4J will pick one logging framework/implementation and bind with it. The way SLF4J picks a binding is determined by the JVM and for all practical purposes should be considered random. As of version 1.6.6, SLF4J will name the framework/implementation class it is actually bound to. Embedded components such as libraries or frameworks should not declare a dependency on any SLF4J binding but only depend on 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. 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.
由于绑定(bind)选择是随机的,我猜测 project-common
SLF4J
依赖项被绑定(bind),而不是来自 logback-classic
的预期依赖项, dropwizard
的传递依赖.您应该排除 project-common
中的那个在你的 Maven 中 pom
文件或更好的是,如果您可以访问 project-common
的代码, 从 pom
中删除它按照链接网页的建议提交文件(即“改过自新”)。
关于java - Dropwizard 应用程序不使用 configuration.yml 中的日志配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34124003/