CeePlusPlus
CeePlusPlus

Reputation: 841

Can't turn off HttpClient Wire debug log messages

I have been trying to set Wire to not send DEBUG to console, but no matter what I do, it won't listen.

I have log4j initialized properly: I do not get any appender messages, log4j is obeying my class and console levels.

In log4j.properties I have every foreseeable way to write wire:

    log4j.logger.org.httpclient=ERROR
    log4j.logger.org.apache=ERROR
    log4j.logger.org.apache.http=ERROR
    log4j.logger.org.apache.http.wire=ERROR
    log4j.logger.org.apache.http.wire.headers=ERROR
    log4j.logger.httpclient.wire=ERROR
    log4j.logger.httpclient.headers=ERROR
    log4j.logger.httpclient.content=ERROR
    log4j.logger.org.apache.hc.client5.http.wire=ERROR
    log4j.logger.httpclient=ERROR
    wire=ERROR
    http=ERROR

I then thought why not print all loggers after calling it? So i did just that. I get a nice printout of everything mentioned above, and my current class. Nothing else prints from iterating through LogManager.getCurrentLoggers()

I think I've read every result on Google at this point. Any guidance would be appreciated.

About the project: Project is a maven Project - pom.xml includes the resource folder. To make this work I literally made a ControlLogging class and PropertyConfiguratior.configure("log4j.properties") is called first. I call this function @Before test runs, and in the static class that's making the API calls. Doing the printing at any point doesn't reveal the Wire logger.

Upvotes: 7

Views: 10184

Answers (2)

Kayden
Kayden

Reputation: 21

Well, I was able to make my log4j properties work using deps:

implementation group: 'org.slf4j', name: 'slf4j-log4j12', version: 1.7.25
implementation group: 'org.slf4j', name: 'slf4j-api', version: 1.7.25
implementation group: 'org.slf4j', name: 'jcl-over-slf4j', version: 1.7.25

or

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.7.25</version>
</dependency>
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
    <version>1.7.25</version>
</dependency>
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>jcl-over-slf4j</artifactId>
    <version>1.7.25</version>
</dependency>

And have a src/java/(main|test)/resources/log4j.properties:

log4j.rootLogger=DEBUG, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%c] %m%n
log4j.logger.org.apache.http=ERROR
log4j.logger.org.apache.http.wire=ERROR

Upvotes: 2

CeePlusPlus
CeePlusPlus

Reputation: 841

So what did finally work for my project was creating a configuration for sl4j / logback -- I couldn't make it work for log4j etc.

So under main/java/resources/logback.xml

<xml version="1.0" encoding="UTF-8" ?>
     <configuration>
     <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
     <encoder>
          <pattern>%d{HH:mm:ss} %thread %-5level %logger{36} %msg%n</pattern>
     </encoder>
     </appender>

     <logger name="org.apache" level="ERROR"/>
     <logger name="httpclient" level="ERROR"/>

     <root level="DEBUG">
          <appender-ref ref="STDOUT" />
     </root>
</configuration>

in maven I simply included dependency for slf4j

 <dependency>
     <groupId>org.slf4j</groupId>
     <artifactId>slf4j-api</artifactId>
 </dependency>
 <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>jcl-over-slf4j</artifactId>
 </dependency>

and its all working now.

Upvotes: 8

Related Questions