如何配置Dropwizard访问日志的位置和旋转?

时间:2013-10-04 11:01:30

标签: logging dropwizard access-log

我的日志配置如下所示:

logging:
  level: INFO

  loggers:
    "com.example.broker": DEBUG
    "org.apache.http.wire": DEBUG

  console:
    threshold: ERROR

  file:
    enabled: true
    currentLogFilename: /opt/broker/log/broker.log
    archivedLogFilenamePattern: /opt/broker/log/broker.%d.log.gz
    archivedFileCount: 14

这太棒了,我通过正确的旋转和清理将所有日志记录在给定的文件中。

除了仍然进入stdout的访问日志,因此在/var/log/upstart/broker.log中结束(在我的情况下)只能由root访问。我想使用相同或类似的日志配置将这些日志重定向到/opt/broker/log/access.log

这可能吗?如果可以,怎么做?

3 个答案:

答案 0 :(得分:23)

自从从codahale迁移到dropwizard.io以来,手册相关部分的位置现在是: http://www.dropwizard.io/0.9.2/docs/manual/configuration.html#request-log

请注意,请求日志现在设置在server而不是http下 - 进行相关的YAML配置:

server:
  requestLog:
    timeZone: UTC
    appenders:
      - type: file
        currentLogFilename: /opt/broker/log/access.log
        threshold: ALL
        archive: true
        archivedLogFilenamePattern: /opt/broker/log/access.%d.log.gz
        archivedFileCount: 14

答案 1 :(得分:10)

阅读documentation实际上有帮助:

http:
    requestLog:
        console:
            enabled: false
        file:
            enabled: true
            currentLogFilename: /opt/broker/log/access.log
            archivedLogFilenamePattern: /opt/broker/log/access.%d.log.gz
            archivedFileCount: 14

答案 2 :(得分:1)

Dropwizard访问日志配置可用here

server:
  requestLog:
    appenders:
      - type: file
        currentLogFilename: /var/log/our-app/access.log
        archivedLogFilenamePattern: /var/log/our-app/accedd-%d.log.gz