简体   繁体   中英

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. This jar also depends on another jar, say b.jar, which uses Apache HTTP client. 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:

[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

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

<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

<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” ? 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. As you can see from this POM , HttpClient uses Apache Commons Logging for its log output instead.

So your goal is to redirect all Commons Logging output via SLF4J to Log4J. This requires two steps:

  1. Add an SLF4J bridge for Commons Logging.
  2. Make sure that the bridge is used as a replacement for 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 . You should be able to achieve both steps with the following new/updated dependencies for your project 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).

(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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM