scalasbtlogbacksbt-onejar

logback.xml not working witn one-jar


I am using sbt one-jar for building an executable jar file in my application. I am also using logback for logging. I am able to get the log file correctly when I run the application in my local. However, after creating one-jar, and executing it, logs are not getting created. I am pasting the logs I get when I start the jar file. I am not able to get that working.

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$

Solution

  • The issue is there are multiple logback configuration files. It is advisable to not package logging config file (logback.xml) inside a JAR file.

    A solution would be to package the application such that your app configuration looks like

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

    You can then pinpoint to your logback.xml by this jvm argument
    -Dlogback.configurationFile="config\logback.xml".