为什么我的 dropwizard 日志记录配置没有应用?

Why isn't my dropwizard logging configuration applied ?

我的 dropwizard 日志仅将所有内容输出到控制台,并输出所有级别的日志记录。我想在开发输出到控制台的过程中为我自己的东西记录一些日志,但过滤掉噪音。我已经坚持了一段时间,自从我升级到 dropwizard 1.0.5 后,我的日志输出太大而且无法使用,无法忽略它。我正在尝试过滤日志记录,但无论我做什么,我的配置都没有被使用。当我 运行 我的 dropwizard 应用程序时,我将所有日志记录输出到控制台

我正在使用以下命令启动

java  \
-Dcom.sun.management.jmxremote  \
-Dcom.sun.management.jmxremote.port=${JMX_PORT}  \
-Dcom.sun.management.jmxremote.rmi.port=${JMX_PORT}  \
-Dcom.sun.management.jmxremote.local.only=false  \
-Dcom.sun.management.jmxremote.authenticate=false  \
-Dcom.sun.management.jmxremote.ssl=false  \
-Djava.rmi.server.hostname=${HOST_IP}  \
-server  \
-classpath "/server/api.jar:/server/config"  \
-Dtm-devops.defaults.file=/server/config/local.properties  \
-Xmx512m  \
-Xms128m  \
-Xdebug  \
-Xrunjdwp:transport=dt_socket,server=y,suspend=${WAIT_DEBUG:-n},address=7878 \
com.tubemogul.api.Application  server config.yaml

config.yaml 在 class 补丁中,它是其中唯一的 yaml 文件。我可以确认对此文件的无效更改已被识别并阻止服务器 运行ning.

我正在尝试应用以下日志记录配置。

logging:

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

  # Logger-specific levels.
  loggers:


    # Sets the level
    io.dropwizard:
      level: WARN
      additive: false
      appenders:
        - type: file
          currentLogFilename: log/dw.log
          archivedLogFilenamePattern: log/dw.%d.log.gz
          archivedFileCount: 5
    org.eclipse: NONE
    org.hibernate:
      level: WARN
      additive: false
      appenders:
        - type: file
          currentLogFilename: log/hib.log
          archivedLogFilenamePattern: log/hib.%d.log.gz
          archivedFileCount: 5
    org.springframework:
      level: WARN
      additive: true
      appenders:
        - type: file
          currentLogFilename: log/spring.log
          archivedLogFilenamePattern: log/spring.%d.log.gz
          archivedFileCount: 5

  appenders:
    - type: console
      threshold: WARN

使用我提供的配置创建了日志文件,但从未写入它们。

我在您的配置中注意到的第一件事是 "org.eclipse" 的级别不正确,因为 "NONE" 不是可接受的级别,这似乎触发了来自 "org.eclipse" 将在控制台中显示的记录器。

org.eclipse: NONE

有趣的是,当我将此记录器的级别更改为 "OFF" 时,出现不支持记录器格式的异常。我已经尝试过在记录器名称上不带引号和带引号都没有运气,因为错误似乎与无效的 JSON 格式有关。这很奇怪,因为 DW 文档显示支持这种格式。

org.eclipse: OFF
"org.eclipse": OFF

Exception in thread "main" java.lang.IllegalArgumentException: Unsupported format of logger 'org.eclipse'

当我更改此记录器以将级别属性作为记录器的 sub-attribute 时,DW 会接受该格式,我不再在控制台中收到此记录器的日志消息。

org.eclipse:
  level: OFF

话虽如此,带有 WARN 阈值的控制台 appender 会阻止所有消息进入控制台,无论是正确的还是错误的级别。我不确定这是否有帮助,但尝试将 "org.eclipse" 更改为另一种格式,也许这会有所帮助,因为我无法使用 DW 1.0.5 复制该问题,因为所有消息都将发送到正确的位置正确的水平。

P.S。我从 Intellij 执行了所有测试,而不是命令。