简体   繁体   English

无法找到正在使用的记录器配置

[英]Unable to locate logger configuration in use

I have a jar, say a.jar, for which I'd like to enable logging only at INFO level. 我有一个jar,例如a.jar,我只想在INFO级别上启用日志记录。 This jar also depends on another jar, say b.jar, which uses Apache HTTP client. 此jar还依赖于另一个使用Apache HTTP客户端的jar,例如b.jar。 When I run my application, I see a lot of debug output on the screen including stuff from the Apache HTTP client in this format alone, irrespective of what I put in the log4j.properties: 运行我的应用程序时,无论我将log4j.properties放在什么内容中,我都会在屏幕上看到很多调试输出,包括来自Apache HTTP客户端的仅此格式的内容。

[com.amazonaws.AmazonWebServiceClient] : Internal logging successfully configured to commons logger: true Ignored FQCN: org.apache.commons.logging.impl.SLF4JLocationAwareLog

For the life of me, I'm unable to figure out where the jars are getting their configuration from. 为了我的一生,我无法弄清楚罐子从哪里得到它们的配置。 Here're things I tried. 这是我尝试过的东西。 1. Added a log4j.properties to only a.jar's main/resources dir 2. Added a log4j.properties to only b.jar's main/resources dir 3. Removed log4j.properties 1.将log4j.properties仅添加到a.jar的main / resources目录中2.将log4j.properties仅添加到b.jar的main / resources目录中3.删除了log4j.properties

Please help me with some inputs as to where the logging configuration may be getting picked up from. 请提供一些有关从何处获取日志记录配置的信息,以帮助我。

Here're pom extracts of a.jar 这是a.jar的pom提取物

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.7.5</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.15</version>
    <scope>compile</scope>
</dependency>

Here's the extract for b.jar 这是b.jar的摘录

<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-api</artifactId>
  <version>1.7.7</version>
  <scope>compile</scope>
</dependency>
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-log4j12</artifactId>
  <version>1.7.7</version>
  <scope>compile</scope>
</dependency>

I assume that you mean this “Apache HTTP client” ? 我假设您是说这个“ Apache HTTP客户端” If so, then your logging configuration for Log4J does not affect the log output of the HttpClient simply because the latter does neither use SLF4J nor Log4J. 如果是这样,则Log4J的日志记录配置不会影响HttpClient的日志输出,这仅仅是因为后者既不使用SLF4J也不使用Log4J。 As you can see from this POM , HttpClient uses Apache Commons Logging for its log output instead. 该POM中可以看到,HttpClient使用Apache Commons Logging代替其日志输出。

So your goal is to redirect all Commons Logging output via SLF4J to Log4J. 因此,您的目标是通过SLF4J将所有Commons Logging输出重定向到Log4J。 This requires two steps: 这需要两个步骤:

  1. Add an SLF4J bridge for Commons Logging. 添加一个SLF4J桥用于Commons Logging。
  2. Make sure that the bridge is used as a replacement for Commons Logging. 确保使用网桥代替Commons Logging。

The bridge to add is described here . 此处描述要添加的桥。 To make sure that the bridge is actually used, I would recommend to exclude the original Commons Logging JAR . 为了确保实际使用了网桥,我建议您排除原始的Commons Logging JAR You should be able to achieve both steps with the following new/updated dependencies for your project B: 您应该能够通过对项目B使用以下新/更新的依赖关系来实现这两个步骤:

<dependency>
  <groupId>org.apache.httpcomponents</groupId>
  <artifactId>httpclient</artifactId>
  <version>4.5.3</version>
  <exclusions>
    <exclusion>
      <groupId>commons-logging</groupId>
      <artifactId>commons-logging</artifactId>
    </exclusion>
  </exclusions>
</dependency>
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>jcl-over-slf4j</artifactId>
  <version>1.7.24</version>
</dependency>

I have added the jcl-over-slf4j bridge in the latest SLF4J version 1.7.24 since it seems that your version of SLF4J (1.7.7) doesn't seem to support Commons Logging 1.2, yet, which might be used by the HttpClient (at least by the one in version 4.5.3). 我在最新的SLF4J版本jcl-over-slf4j添加了jcl-over-slf4j桥,因为似乎您的SLF4J版本(1.7.7)似乎不支持Commons Logging 1.2,但是HttpClient可能会使用它(至少是版本4.5.3中的版本)。

(Note that I haven't tested this. But the eventual solution should at least be pretty similar to the described approach.) (请注意,我尚未对此进行测试。但是最终的解决方案至少应该与所述方法非常相似。)

Looking at this , it seems like one of the amazon sdk jars is the place this logging configuration would be present in. 看着这个 ,似乎是一个sdk jars日志存储配置所在的地方。

It uses apache commons logging and any configuration that you are doing in your project is being done for slf4j and hence is not taking any effect. 它使用apache commons日志记录,并且您正在slf4j中完成项目中正在执行的任何配置,因此不起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 主要错误无法找到记录器配置“测试”的附加程序“测试” - main ERROR Unable to locate appender "test" for logger config "test" Spring配置:无法找到Spring NamespaceHandler - Spring configuration: Unable to locate Spring NamespaceHandler Spring Security Configuration无法找到NameSpaceHandler - Spring Security Configuration unable locate NameSpaceHandler Spring Bean 无法找到配置属性 Bean - Spring Bean Unable to Locate Configuration Properties Bean log4j gradle配置-无法找到实现错误 - log4j gradle configuration - Unable to locate implementation error 配置问题:无法找到XML模式命名空间的Spring NamespaceHandler - Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace java.lang.SecurityException:无法找到登录配置 - java.lang.SecurityException: Unable to locate a login configuration 无法使用 Spring Java 配置中的 ClassPathResource 找到 xml 文件 - Unable to locate xml file using ClassPathResource in Spring Java configuration Quarkus 无法使用外部配置 - Unable to use external configuration with Quarkus 没有这样的元素:无法找到元素:当我使用elementToBeClickable方法时 - no such element: Unable to locate element: when I use elementToBeClickable method
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM