logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Douglas E Wegscheid <Douglas_E_Wegsch...@whirlpool.com>
Subject Re: Log4J doesn't work at all
Date Wed, 11 Apr 2012 12:36:29 GMT
tommmmmm <tommmmmm@gmail.com> wrote on 04/11/2012 01:28:23 AM:

> >
> > You indicated that you were going to grab a fresh commons-logging jar 
and
> > use it. Did you, or did that step get lost in the shuffle?
> 
> 
> I did. Did not help. Fyi, it was also 60KB+

I made a new project in Eclipse, added all the jar files in 
httpcomponents-client-4.1.3 GA to a /lib folder, added log4j-1.2.16.jar to 
the same folder, put all the jars in that folder on my classpath, added 
these two files to src folder:

Test1.java:

import org.apache.http.*;
import org.apache.http.client.*;
import org.apache.http.client.methods.HttpHead;
import org.apache.http.impl.client.DefaultHttpClient;
// import org.apache.log4j.PropertyConfigurator;

public class Test1 {
  public static void main (String[] args) {
     System.setProperty("log4j.debug", "true");
     // PropertyConfigurator.configure("log4j.properties");
     int i = new Test1(args).go();
     System.exit(i);
  }
 
  org.apache.log4j.Logger log4j = org.apache.log4j.Logger.getLogger(
"test.log4j");
  org.apache.commons.logging.Log commons = 
org.apache.commons.logging.LogFactory.getLog("test.commons");
  org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger
(getClass());
 
  Test1 (String[] args) {
    super();
  }
 
  int go () {
    Throwable boom = null; 
    try {
      logger.info("greeting from logger");
      log4j.info("greeting from log4j");
      commons.info("greeting from commons");
      HttpClient httpClient = new DefaultHttpClient();
      HttpHead httpRequest = new HttpHead("http://xxxxxxxxxxxxxx/");
      HttpResponse httpResponse = httpClient.execute(httpRequest);
      logger.info("response = " + httpResponse.toString());
    } catch (RuntimeException ex) {
      boom = ex;
    } catch (ClientProtocolException ex) {
      boom = ex;
    } catch (IOException ex) {
      boom = ex;
    }
    if (boom != null) boom.printStackTrace();
    return 0;
  }

}

log4j.properties:

log4j.properties:

log4j.rootLogger=INFO,stdout

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=from Log4J: %5p [%c] %m%n

log4j.logger.org.apache.http=DEBUG
log4j.logger.org.apache.http.wire=ERROR

my output looks as I would expect (hostnames are xxxxxxxxxxxxxx'd out)

log4j: Trying to find [log4j.xml] using context classloader 
sun.misc.Launcher$AppClassLoader@35ce36.
log4j: Trying to find [log4j.xml] using 
sun.misc.Launcher$AppClassLoader@35ce36 class loader.
log4j: Trying to find [log4j.xml] using ClassLoader.getSystemResource().
log4j: Trying to find [log4j.properties] using context classloader 
sun.misc.Launcher$AppClassLoader@35ce36.
log4j: Using URL 
[file:/D:/data/Workspace-GJobs/HttpClient/bin/log4j.properties] for 
automatic log4j configuration.
log4j: Reading configuration from URL 
file:/D:/data/Workspace-GJobs/HttpClient/bin/log4j.properties
log4j: Parsing for [root] with value=[INFO,stdout].
log4j: Level token is [INFO].
log4j: Category root set to INFO
log4j: Parsing appender named "stdout".
log4j: Parsing layout options for "stdout".
log4j: Setting property [conversionPattern] to [from Log4J: %5p [%c] 
%m%n].
log4j: End of parsing for "stdout".
log4j: Parsed "stdout" options.
log4j: Parsing for [org.apache.http.wire] with value=[ERROR].
log4j: Level token is [ERROR].
log4j: Category org.apache.http.wire set to ERROR
log4j: Handling log4j.additivity.org.apache.http.wire=[null]
log4j: Parsing for [org.apache.http] with value=[DEBUG].
log4j: Level token is [DEBUG].
log4j: Category org.apache.http set to DEBUG
log4j: Handling log4j.additivity.org.apache.http=[null]
log4j: Finished configuring.
from Log4J:  INFO [Test1] greeting from logger
from Log4J:  INFO [test.log4j] greeting from log4j
from Log4J:  INFO [test.commons] greeting from commons
from Log4J: DEBUG [org.apache.http.impl.conn.SingleClientConnManager] Get 
connection for route HttpRoute[{}->http://xxxxxxxxxxxxxxxxxxxxxxx]
from Log4J: DEBUG 
[org.apache.http.impl.conn.DefaultClientConnectionOperator] Connecting to 
xxxxxxxxxxxxxxxxxxx:80
from Log4J: DEBUG [org.apache.http.client.protocol.RequestAddCookies] 
CookieSpec selected: best-match
from Log4J: DEBUG [org.apache.http.client.protocol.RequestAuthCache] Auth 
cache not set in the context
from Log4J: DEBUG [org.apache.http.impl.client.DefaultHttpClient] Attempt 
1 to execute request
from Log4J: DEBUG [org.apache.http.impl.conn.DefaultClientConnection] 
Sending request: HEAD / HTTP/1.1
from Log4J: DEBUG [org.apache.http.headers] >> HEAD / HTTP/1.1
from Log4J: DEBUG [org.apache.http.headers] >> Host: 
xxxxxxxxxxxxxxxxxxxxxxxxxx
from Log4J: DEBUG [org.apache.http.headers] >> Connection: Keep-Alive
from Log4J: DEBUG [org.apache.http.headers] >> User-Agent: 
Apache-HttpClient/4.1.3 (java 1.5)
from Log4J: DEBUG [org.apache.http.impl.conn.DefaultClientConnection] 
Receiving response: HTTP/1.1 200 OK
from Log4J: DEBUG [org.apache.http.headers] << HTTP/1.1 200 OK
from Log4J: DEBUG [org.apache.http.headers] << Date: Wed, 11 Apr 2012 
12:28:02 GMT
from Log4J: DEBUG [org.apache.http.headers] << Server: Apache/2.2.15 (Red 
Hat)
from Log4J: DEBUG [org.apache.http.headers] << Last-Modified: Mon, 16 May 
2011 14:39:57 GMT
from Log4J: DEBUG [org.apache.http.headers] << ETag: 
"1660006-129-4a365a1278f31"
from Log4J: DEBUG [org.apache.http.headers] << Accept-Ranges: bytes
from Log4J: DEBUG [org.apache.http.headers] << Content-Length: 297
from Log4J: DEBUG [org.apache.http.headers] << Keep-Alive: timeout=15, 
max=100
from Log4J: DEBUG [org.apache.http.headers] << Connection: Keep-Alive
from Log4J: DEBUG [org.apache.http.headers] << Content-Type: text/html; 
charset=UTF-8
from Log4J: DEBUG [org.apache.http.impl.client.DefaultHttpClient] 
Connection can be kept alive for 15000 MILLISECONDS
from Log4J: DEBUG [org.apache.http.impl.conn.SingleClientConnManager] 
Releasing connection 
org.apache.http.impl.conn.SingleClientConnManager$ConnAdapter@4413ee
from Log4J:  INFO [Test1] response = HTTP/1.1 200 OK [Date: Wed, 11 Apr 
2012 12:28:02 GMT, Server: Apache/2.2.15 (Red Hat), Last-Modified: Mon, 16 
May 2011 14:39:57 GMT, ETag: "1660006-129-4a365a1278f31", Accept-Ranges: 
bytes, Content-Length: 297, Keep-Alive: timeout=15, max=100, Connection: 
Keep-Alive, Content-Type: text/html; charset=UTF-8]

it can work: you just need to discover what's different between my case 
and yours.

■ DOUGLAS E. WEGSCHEID // LEAD ENGINEER
(269) 923-5278 // Douglas_E_Wegscheid@whirlpool.com
"A wrong note played hesitatingly is a wrong note. A wrong note played 
with conviction is interpretation."


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