hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bill Speirs <bill.spe...@gmail.com>
Subject Re: How to use logging abilities of HttpClient?
Date Wed, 11 Apr 2012 13:05:37 GMT

HttpClient is not the issue here, it is commons-logging... please don't
accuse libraries/groups, especially when they are trying to help you.

>From the commons-logging "Quick Start" guide: "As far as possible, JCL
tries to be as unobtrusive as possible. In most cases, including the (full)
commons-logging.jar in the classpath should result in JCL configuring
itself in a reasonable manner. There's a good chance that it'll guess
(discover) your preferred logging system and you won't need to do any
configuration of JCL at all! Note, however, that if you have a particular
preference then *providing a simple commons-logging.properties file which
specifies the concrete logging library to be used is recommended*, since
(in this case) JCL will log only to that system and will report any
configuration problems that prevent that system being used." [1]

To ensure that commons-logging is using the log4j implementation that
you've specified, add commons-logging.properties to your class path with
the following
line: org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger

This will tell commons-logging which logging implementation, log4j in this
case, to use. Because HttpClient is using commons-logging for all of its
logs, this will send those logs to your log4j setup.

Why do you have to do this at all? Commons-logging tries to guess which
logging framework you'd like to use. For some reason, I'm not going to
attempt to figure out why but the source is all there if you want to have a
look, commons-logging is probably finding the java.util.logging
implementation and trying to use that. Because you don't have it setup,
those messages are going away.

I hope this helps.

[1]  http://commons.apache.org/logging/guide.html#Quick Start


On Wed, Apr 11, 2012 at 5:44 AM, tommmmmm <tommmmmm@gmail.com> wrote:
> 2 relevant things:
> 1) Output of:
> is:
> null
> null
> null
> 2) I created a StupidClass in some OTHER package:
> public class StupidClass {
>    private static Logger logger = Logger.getLogger("tests.StupidClass");
>    public void logSmth() {
>        logger.debug("stupid class debug logger test");
>    }
> }
> Then added this to config file:
> log4j.logger.stupidClass=DEBUG
> Then did this in my main class:
>        StupidClass c = new StupidClass();
>        c.logSmth();
> And I got this output:
> DEBUG [tests.StupidClass] stupid class debug logger test
> And that ladies and gentleman is an ultimate proof that it's HttpClient's
> fault that logging doesn't work at all. Because from application's point
> view, the class StupidClass and HttpClient are the same <=> a class
> a package. And log4j CAN communicate with class outside of package very
> well and very easily - it is HttpClient that is delibaretly IGNORING those
> calls from log4j. So fixing the logging issues was a dead end from the
> beginning - because what must be fixed is HttpClient itself and not
> thingies.
> So the question is: why HttpClient ignores log4j ?

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message