4

I'm trying to disable request level logging by the AWS Java SDK with Tomcat 8 on Linux. It's a fresh installation of tomcat 8 and my test servlet (which works) just prints to standard out, which by default goes to /var/log/tomcat8/catalina.out.

I'd like to disable the request level logging like - Sending Request... by the AWS SDK, so I've tried adding the following to my logging config at /usr/share/tomcat8/conf/logging.properties:

log4j.logger.com.amazonaws = WARN
log4j.logger.org.apache.http.wire = WARN
log4j.logger.com.amazonaws.request = WARN

...like the docs say here, but it's still doing the verbose logging. My tomcat startup information shows that the logging.properties file is being used:

org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/usr/share/tomcat8/conf/logging.properties  

Is there anything else I need to do to?

RTF
  • 6,214
  • 12
  • 64
  • 132

4 Answers4

3

If you are using Logback, instead of Log4J or Java14 logging, put the following in logback.xml:

<configuration>
    ...

    <logger name="org.apache.http.wire" level="WARN"/>
    <logger name="com.amazonaws" level="WARN"/>
    ...    

To specify an external logback.xml and using Spring Boot

-Dlogging.config="C:\logback\logback.xml"

or if you are not

-Dlogback.configurationFile=file:///C:/logback/logback.xml

Logback configuration via jvm argument

JustinKSU
  • 4,875
  • 2
  • 29
  • 51
2

I had the same issue, none of the above helped actually.

Creating a logback.xml and putting it on classpath with below config fixed it:

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

Hope it helps the others.

Akki
  • 73
  • 1
  • 11
1

"logging.properties" is the configuration file for Java Util Logging (JUL), witch is a different framework then Log4J. You can try to create a Log4J config file "log4j.properties" in the root of your classpath and insert the code from above: "log4j.logger.com.amazonaws = WARN" .

Stefan
  • 12,108
  • 5
  • 47
  • 66
  • There is documentation for configuring of log4j https://docs.aws.amazon.com/java-sdk/latest/developer-guide/java-dg-logging.html. You have to set `log4j.logger.org.apache.http.wire=WARN` also. – shobull Aug 18 '16 at 13:34
1

By Mark

Perhaps I should have been clearer: log4j is not required to control logging in the SDK. The SDK uses Apache Commons Logging, which is, as I already mentioned, an industry standard. Commons Logging is just a dispatch layer to an underlying logging implementation, so that customers can plug in any compliant logging framework and have it work. I used log4j in my examples because it's the one most commonly used, and therefore the most likely to be helpful in this public forum.

If your logging system works with Commons Logging, then you already know how to configure it. If it doesn't, then feel free to turn off Commons Logging altogether by passing the appropriate command-line argument to your JVM, as in my above response. If for some reason you can't change the java command line for your application, then you can use the following snippet in a Main class, to the same effect:

static {
      System.setProperty("org.apache.commons.logging.Log",
                         "org.apache.commons.logging.impl.NoOpLog");
   }

Again, to be absolutely clear: the SDK doesn't need log4j. Unfortunately, because all the underlying log implementations are configured differently, this means that we can't tell you exactly how to configure the logging unless we know which implementation your application uses. For that reason, we often use log4j syntax in our examples.

For more information about how Apache Commons Logging works and how to configure it, please read:

http://commons.apache.org/logging/guide.html

samba
  • 61
  • 5