【问题标题】:Why can't dropwizard configure my logger?为什么 dropwizard 无法配置我的记录器?
【发布时间】:2016-06-21 12:39:51
【问题描述】:

我只是想将日志配置添加到 dropwizard 的 yaml 配置文件中。我正在运行 dropwizard 0.9.2 版,我的 yaml 包含以下内容:

logging:
  level: INFO
  appenders:
    - type: file
      currentLogFilename: ./log/mylogfile.log
      threshold: ALL
      archive: true
      archivedLogFilenamePattern: ./log/mylogfile-%d{yyyy-MM-dd-HH}.log
      archivedFileCount: 5
      timeZone: UTC
      logFormat: # TODO

我的fatjar肯定有

META-INF/services/io.dropwizard.logging.AppenderFactory

其中包含

io.dropwizard.logging.ConsoleAppenderFactory
io.dropwizard.logging.FileAppenderFactory
io.dropwizard.logging.SyslogAppenderFactory

但我在启动时得到这个...

9:29:28 AM web.1 |    * Failed to parse configuration at: logging.appenders.[0]; Could not resolve type id 'file' into a subtype of [simple type, class io.dropwizard.logging.AppenderFactory]: known type ids = [AppenderFactory]
9:29:28 AM web.1 |   at [Source: N/A; line: -1, column: -1] (through reference chain: com.salesforce.analytics.query.AppConfiguration["logging"]->io.dropwizard.logging.DefaultLoggingFactory["appenders"]->java.util.ArrayList[0])

任何关于我做错了什么的帮助??

【问题讨论】:

  • 只有在你的 fat-jar 运行时才会发生这种情况?您的类路径配置正确吗?
  • 是的,这是一个 fatjar,类路径上还需要其他东西吗?

标签: java logging jetty dropwizard


【解决方案1】:

请检查您是否在 yml 文件中使用制表符而不是使用双倍空格我正在使用以下日志配置及其工作正常,还验证您需要包含 maven shade 插件的 pom 文件还添加了我的 pom 文件的构建部分

logging:
  # The default level of all loggers. Can be OFF, ERROR, WARN, INFO, DEBUG, TRACE, or ALL.
  level: INFO
  loggers:
    "org.skife.jdbi.v2": TRACE
  appenders:
    - type: file
      # The file to which current statements will be logged.
      currentLogFilename: ./logs/mylogfile.log

      # When the log file rotates, the archived log will be renamed to this and gzipped. The
      # %d is replaced with the previous day (yyyy-MM-dd). Custom rolling windows can be created
      # by passing a SimpleDateFormat-compatible format as an argument: "%d{yyyy-MM-dd-hh}".
      archivedLogFilenamePattern: ./logs/mylogfile-%d.log.gz

      # The number of archived files to keep.
      archivedFileCount: 5

      # The timezone used to format dates. HINT: USE THE DEFAULT, UTC.
      timeZone: UTC

pom 文件插件

<build>
        <plugins>
            <plugin>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.4.1</version>
                <configuration>
                    <createDependencyReducedPom>true</createDependencyReducedPom>
                    <transformers>
                        <transformer
                            implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
                        <transformer
                            implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                            <mainClass>${mainClass}</mainClass>
                        </transformer>
                    </transformers>
                    <!-- exclude signed Manifests -->
                    <filters>
                        <filter>
                            <artifact>*:*</artifact>
                            <excludes>
                                <exclude>META-INF/*.SF</exclude>
                                <exclude>META-INF/*.DSA</exclude>
                                <exclude>META-INF/*.RSA</exclude>
                            </excludes>
                        </filter>
                    </filters>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <mainClass>${mainClass}</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-source-plugin</artifactId>
                <version>2.4</version>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>2.10.3</version>
                <executions>
                    <execution>
                        <id>attach-javadocs</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

【讨论】:

    猜你喜欢
    • 2018-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-26
    • 1970-01-01
    • 2014-09-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多