0

我正在使用 sbtone-jar在我的应用程序中构建一个可执行的 jar 文件。我也在使用 logback 进行日志记录。当我在本地运行应用程序时,我能够正确获取日志文件。但是,在创建 one-jar 并执行它之后,不会创建日志。我正在粘贴启动 jar 文件时得到的日志。我无法让它工作。

JarClassLoader: Warning: Null manifest from input stream associated with: lib/aspectjweaver-1.7.2.jar
JarClassLoader: Warning: Null manifest from input stream associated with: lib/aspectjrt-1.7.2.jar
JarClassLoader: Warning: play/core/server/ServerWithStop.class in lib/build-link-2.3.6.jar is hidden by lib/play_2.11-2.3.6.jar (with different bytecode)
JarClassLoader: Warning: org/apache/commons/logging/impl/NoOpLog.class in lib/jcl-over-slf4j-1.7.6.jar is hidden by lib/commons-logging-1.1.1.jar (with different bytecode)
JarClassLoader: Warning: org/apache/commons/logging/impl/SimpleLog$1.class in lib/jcl-over-slf4j-1.7.6.jar is hidden by lib/commons-logging-1.1.1.jar (with different bytecode)
JarClassLoader: Warning: org/apache/commons/logging/impl/SimpleLog.class in lib/jcl-over-slf4j-1.7.6.jar is hidden by lib/commons-logging-1.1.1.jar (with different bytecode)
JarClassLoader: Warning: org/apache/commons/logging/Log.class in lib/jcl-over-slf4j-1.7.6.jar is hidden by lib/commons-logging-1.1.1.jar (with different bytecode)
JarClassLoader: Warning: org/apache/commons/logging/LogConfigurationException.class in lib/jcl-over-slf4j-1.7.6.jar is hidden by lib/commons-logging-1.1.1.jar (with different bytecode)
JarClassLoader: Warning: org/apache/commons/logging/LogFactory.class in lib/jcl-over-slf4j-1.7.6.jar is hidden by lib/commons-logging-1.1.1.jar (with different bytecode)
16:58:32,500 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
16:58:32,500 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
16:58:32,500 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [jar:file:/common-api_2.11-0.1-SNAPSHOT-one-jar.jar!/lib/play_2.11-2.3.6.jar!/logback.xml]
16:58:32,501 |-WARN in ch.qos.logback.classic.LoggerContext[default] - Resource [logback.xml] occurs multiple times on the classpath.
16:58:32,501 |-WARN in ch.qos.logback.classic.LoggerContext[default] - Resource [logback.xml] occurs at [jar:file:/common-api_2.11-0.1-SNAPSHOT-one-jar.jar!/main/common-api_2.11-0.1-SNAPSHOT.jar!/logb
ack.xml]
16:58:32,501 |-WARN in ch.qos.logback.classic.LoggerContext[default] - Resource [logback.xml] occurs at [jar:file:/common-api_2.11-0.1-SNAPSHOT-one-jar.jar!/lib/play_2.11-2.3.6.jar!/logback.xml]
16:58:32,513 |-INFO in ch.qos.logback.core.joran.spi.ConfigurationWatchList@27cfc9a3 - URL [jar:file:/common-api_2.11-0.1-SNAPSHOT-one-jar.jar!/lib/play_2.11-2.3.6.jar!/logback.xml] is not of type fil
e
16:58:32,636 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
16:58:32,644 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
16:58:32,648 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [STDOUT]
16:58:32,662 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
16:58:32,681 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to ERROR
16:58:32,681 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[ROOT]
16:58:32,682 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
16:58:32,682 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@72c84bd5 - Registering current configuration as safe fallback point

SLF4J: The following set of substitute loggers may have been accessed
SLF4J: during the initialization phase. Logging calls during this
SLF4J: phase were not honored. However, subsequent logging calls to these
SLF4J: loggers will work as normally expected.
SLF4J: See also http://www.slf4j.org/codes.html#substituteLogger
SLF4J: com.reactore.common.feature.security.domain.FeatureRepository$
4

1 回答 1

0

问题是有多个 logback 配置文件。建议不要将日志记录配置文件 (logback.xml) 打包到 JAR 文件中。

一个解决方案是打包应用程序,使您的应用程序配置看起来像

my-app/
  bin/
    run-app.sh
  config/
    logback.xml
  lib/
    my-app.jar

然后,您可以通过此 jvm 参数精确定位到您的 logback.xml
-Dlogback.configurationFile="config\logback.xml".

于 2014-12-09T12:00:29.250 回答