我只是尝试将日志配置添加到 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])
关于我做错了什么有什么帮助吗?
最佳答案
请检查您的 yml 文件中是否使用制表符,而不是使用双空格,我正在使用以下日志配置及其工作正常,还要验证您的 pom 文件,您需要包含 Maven Shade 插件,还添加了我的 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>
关于java - 为什么 dropwizard 无法配置我的记录器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37944703/