logback忽略了我的logback.xml

时间:2017-07-05 23:18:34

标签: scala logging logback

我有一个sbt / scala项目,其中包含依赖项“ch.qos.logback”%“logback-classic”%“1.0.13”,并包含一个logback.xml文件,其内容如下:

<configuration debug="true">
    <logger name="com.typesafe.sslconfig.ssl.ConfigSSLContextBuilder" level="ERROR"/>
    <logger name="com.typesafe.sslconfig.ssl.AlgorithmChecker" level="ERROR"/>

    <root level="ERROR">
        <appender class="ch.qos.logback.core.ConsoleAppender">
            <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
                <pattern>%d{ISO8601} | %-5level | %thread | %logger{1} | %m%n</pattern>
            </encoder>
        </appender>
    </root>
</configuration>

https://pastebin.com/S1qauMi9  

当我运行程序时,我得到输出:

[WARN] [07/05/2017 16:01:25.782] [main] [com.typesafe.sslconfig.ssl.ConfigSSLContextBuilder] validateStore: Skipping certificate with weak key size in thawtepremiumserverca: Certificate failed: cert = "1.2.840.113549.1.9.1=#16197072656d69756d2d736572766572407468617774652e636f6d,CN=Thawte Premium Server CA,OU=Certification Services Division,O=Thawte Consulting cc,L=Cape Town,ST=Western Cape,C=ZA" failed on constraint RSA keySize < 2048, algorithm = RSA, keySize = 1024
[WARN] [07/05/2017 16:01:25.782] [main] [com.typesafe.sslconfig.ssl.ConfigSSLContextBuilder] validateStore: Skipping certificate with weak key size in thawteserverca: Certificate failed: cert = "1.2.840.113549.1.9.1=#16177365727665722d6365727473407468617774652e636f6d,CN=Thawte Server CA,OU=Certification Services Division,O=Thawte Consulting cc,L=Cape Town,ST=Western Cape,C=ZA" failed on constraint RSA keySize < 2048, algorithm = RSA, keySize = 1024 

...

16:01:25,822 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
16:01:25,822 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
16:01:25,822 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [jar:file:/Users/eswenson/Projects/Modulus/ws/modulus-shared-libraries/modules/dataset-client-cli/target/scala-2.11/dataset-client-cli-assembly-1.0.dev.jar!/logback.xml]
16:01:25,833 |-INFO in ch.qos.logback.core.joran.spi.ConfigurationWatchList@1eaf1e62 - URL [jar:file:/Users/eswenson/Projects/Modulus/ws/modulus-shared-libraries/modules/dataset-client-cli/target/scala-2.11/dataset-client-cli-assembly-1.0.dev.jar!/logback.xml] is not of type file
16:01:25,873 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [com.typesafe.sslconfig.ssl.ConfigSSLContextBuilder] to ERROR
16:01:25,873 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [com.typesafe.sslconfig.ssl.AlgorithmChecker] to ERROR
16:01:25,873 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to ERROR
16:01:25,907 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
16:01:25,908 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@6fd1660 - Registering current configuration as safe fallback point
[WARN] [07/05/2017 16:01:26.084] [main] [com.typesafe.sslconfig.ssl.ConfigSSLContextBuilder] validateStore: Skipping certificate with weak key size in thawtepremiumserverca: Certificate failed: cert = "1.2.840.113549.1.9.1=#16197072656d69756d2d736572766572407468617774652e636f6d,CN=Thawte Premium Server CA,OU=Certification Services Division,O=Thawte Consulting cc,L=Cape Town,ST=Western Cape,C=ZA" failed on constraint RSA keySize < 2048, algorithm = RSA, keySize = 1024
[WARN] [07/05/2017 16:01:26.085] [main] [com.typesafe.sslconfig.ssl.ConfigSSLContextBuilder] validateStore: Skipping certificate with weak key size in thawteserverca: Certificate failed: cert = "1.2.840.113549.1.9.1=#16177365727665722d6365727473407468617774652e636f6d,CN=Thawte Server CA,OU=Certification Services Division,O=Thawte Consulting cc,L=Cape Town,ST=Western Cape,C=ZA" failed on constraint RSA keySize < 2048, algorithm = RSA, keySize = 1024

Full log here:  https://pastebin.com/6Xd10TZZ

两个问题:

1)为什么在logback之前出现了java日志记录输出?如何确保首先初始化logback?

2)为什么记录com.typesafe.sslconfig.ssl.ConfigSSLContextBuilder中的所有警告,当我明确设置这些警告的级别为ERROR时?

我启用了logback配置调试,以便您可以看到logback确实声称将此类的loglevel设置为ERROR。但仍会记录消息。

2 个答案:

答案 0 :(得分:0)

root-tag中允许的唯一标记是appender-ref,您可以通过名称[1]引用先前定义的appender。将appender定义移动到配置的开头,并仅在根目录中引用它。此外,如果您对logback配置的理解是基本的,那么您应该首先阅读手册[2]。

[1] https://logback.qos.ch/manual/configuration.html#rootElement

[2] https://logback.qos.ch/manual/index.html

答案 1 :(得分:0)

问题结果是事实(我仍然不明白为什么会这样),以下akka配置逻辑:

akka {
  loglevel = "ERROR"
  stdout-loglevel = "ERROR"
  loggers = ["akka.event.slf4j.Slf4jLogger"]
}

包含在CLI实用程序使用的库中的reference.conf中,需要添加到CLI JAR中尚未存在的application.conf中。虽然我不明白为什么这是必要的,但它导致问题消失。我原以为在库中包含一个reference.conf,如果没有被库的调用者中的相应配置覆盖,仍然会生效。显然,我错了。