Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to disable the org.apache.http.wire DEBUG log #77

Open
yqbjtu opened this issue Apr 28, 2016 · 9 comments
Open

How to disable the org.apache.http.wire DEBUG log #77

yqbjtu opened this issue Apr 28, 2016 · 9 comments

Comments

@yqbjtu
Copy link

yqbjtu commented Apr 28, 2016

I used the file upload function, but there is many http debug log. I start the upload by a separate process(Main program runs, when needed, it will start upload small program), so I can't added the -Dxxx=yyyy to the java starting arguments. Any help is appreciated. Thank you!

16:02:09.497 [main] DEBUG org.apache.http.wire - >> "Accept: application/json, application/javascript, text/javascript[\r][\n]"
16:02:09.497 [main] DEBUG org.apache.http.wire - >> "Authorization: Basic YWRtaW46cGFzc3dvcmQ=[\r][\n]"
16:02:09.497 [main] DEBUG org.apache.http.wire - >> "User-Agent: Artifactory-Client/1.0[\r][\n]"
16:02:09.497 [main] DEBUG org.apache.http.wire - >> "Content-Length: 4646[\r][\n]"
16:02:09.497 [main] DEBUG org.apache.http.wire - >> "Content-Type: application/octet-stream[\r][\n]"
16:02:09.497 [main] DEBUG org.apache.http.wire - >> "Host: 127.0.0.1:8081[\r][\n]"
16:02:09.497 [main] DEBUG org.apache.http.wire - >> "Connection: Keep-Alive[\r][\n]"

@lev112
Copy link

lev112 commented Oct 19, 2016

you can configure logback with a config file like this on logback.xml

If you want to disable programmatically, you can use this sample code (it's in scala, but java will be very similar):

import org.slf4j.LoggerFactory
import ch.qos.logback.classic.Level
import ch.qos.logback.classic.Logger

val loggers = Seq(
"org.apache.http",
"groovyx.net.http"
)

loggers.foreach { name =>
  val logger = LoggerFactory.getLogger(name).asInstanceOf[Logger]
  logger.setLevel(Level.INFO)
  logger.setAdditive(false)
}

@terrytheplatypus
Copy link

terrytheplatypus commented Jul 12, 2017

Here is Java code of the above for lazy people, the imports are the same. :

    Set<String> loggers = new HashSet<>(Arrays.asList("org.apache.http", "groovyx.net.http"));
    
    for(String log:loggers) { 
    Logger logger = (Logger)LoggerFactory.getLogger(log);
    logger.setLevel(Level.INFO);
    logger.setAdditive(false);
    }

However, this does not work in gnome-terminal because of this error:
org.slf4j.impl.SimpleLogger cannot be cast to ch.qos.logback.classic.Logger

@milind94
Copy link

milind94 commented Dec 2, 2017

Create a logback.xml with below contents:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <logger name="org.apache" level="ERROR" />
    <logger name="httpclient" level="ERROR" />
</configuration>

Then put this logback.xml in your java source dir so it will be included in jar file. Otherwise create a jar from logback.xml and put this jar to your lib where you fetch all your jars.

A simple way to create logback.jar from logback.xml is using ant.
Create build.xml with below code:

<?xml version='1.0'?>
<project name="test" default="compile" basedir=".">
<target name = "build-jar">
   <jar destfile = "op/logback.jar"
      basedir = "in">
      <manifest>
        <attribute name = "Main-Class" value = "com.tutorialspoint.util.FaxUtil"/>
      </manifest>
   </jar>
</target>
</project>

Create a directory structure like:
.
|-- build.xml
|-- in --> logback.xml
|-- op --> logback.jar //This will be generated after execution of ant command

Now compile using ant build-jar
You will have logback.jar. Put this jar with all other jars and it will remove org.apache.http.wire DEBUG log

Thanks.

@ghost
Copy link

ghost commented Aug 20, 2018

it works for me . Thanks @terrytheplatypus

@Dougnlizt
Copy link

Dougnlizt commented Mar 26, 2019

Piggy-backing off of @terrytheplatypus and the code there, in order to avoid conflicts with using Java's util logger (or other logger you may be using), you can instead explicitly include the package like this:

Set<String> artifactoryLoggers = new HashSet<>(Arrays.asList("org.apache.http", "groovyx.net.http"));
for(String log:artifactoryLoggers) {
    ch.qos.logback.classic.Logger artLogger = (ch.qos.logback.classic.Logger) org.slf4j.LoggerFactory.getLogger(log);
    artLogger.setLevel(ch.qos.logback.classic.Level.INFO);
    artLogger.setAdditive(false);
}

@rage-shadowman
Copy link

Set<String> artifactoryLoggers = new HashSet<>(Arrays.asList("org.apache.http", "groovyx.net.http"));
for(String log:artifactoryLoggers) {
    ch.qos.logback.classic.Logger artLogger = (ch.qos.logback.classic.Logger) org.slf4j.LoggerFactory.getLogger(log);
    artLogger.setLevel(ch.qos.logback.classic.Level.INFO);
    artLogger.setAdditive(false);
}

@Dougnlizt Is there a logback config file setting to make this work?

Sadly, the following doesn't work for me even though the above programmatic setting does:

<logger name="org.apache.http" level="INFO" additive="false"/>
<logger name="groovyx.net.http" level="INFO" additive="false"/>

Even bumping my root log level up to INFO in the logback config file fails to stop these DEBUG logs.

@MistRay
Copy link

MistRay commented Apr 16, 2020

Very helpful,thank you. @Dougnlizt

@ranahosur
Copy link

Create a logback.xml with below contents:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <logger name="org.apache" level="ERROR" />
    <logger name="httpclient" level="ERROR" />
</configuration>

Then put this logback.xml in your java source dir so it will be included in jar file. Otherwise create a jar from logback.xml and put this jar to your lib where you fetch all your jars.

A simple way to create logback.jar from logback.xml is using ant.
Create build.xml with below code:

<?xml version='1.0'?>
<project name="test" default="compile" basedir=".">
<target name = "build-jar">
   <jar destfile = "op/logback.jar"
      basedir = "in">
      <manifest>
        <attribute name = "Main-Class" value = "com.tutorialspoint.util.FaxUtil"/>
      </manifest>
   </jar>
</target>
</project>

Create a directory structure like:
.
|-- build.xml
|-- in --> logback.xml
|-- op --> logback.jar //This will be generated after execution of ant command

Now compile using ant build-jar
You will have logback.jar. Put this jar with all other jars and it will remove org.apache.http.wire DEBUG log

Thanks.

Awesome. This saved me

@atul-epam
Copy link

@milind94 It did not work for me. I created the logback.xml file with exactly same content and added in resource folder and created jar file but I still see those logs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants