Log4J doesn't work at all
From: http://hc.apache.org/httpcomponents-client-ga/logging.html I copy pasted log4j.rootLogger=INFO, 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=DEBUG log4j.logger.org.apache.http.wire=ERROR Into a file I named log4j.properties that I put into src folder a'ka default package Didn't work at all. Then I put this in my class: System.setProperty(log4j.rootLogger, INFO, stdout); System.setProperty(log4j.appender.stdout, org.apache.log4j.ConsoleAppender); System.setProperty(log4j.appender.stdout.layout, org.apache.log4j.PatternLayout); System.setProperty(log4j.appender.stdout.layout.ConversionPattern, %5p [%c] %m%n); System.setProperty(log4j.logger.org.apache.http.client, DEBUG); System.setProperty(log4j.logger.org.apache.http, DEBUG); System.setProperty(log4j.logger.org.apache.http.wire, DEBUG); Yet it didn't work at all either. No additional output was produced. How do you make it work? ps: at: http://logging.apache.org/log4j/1.2/manual.html It's not written how to do it (empty paragraph Example Configurations and non empty yet ultimately useless Tomcat paragraph).
Re: Log4J doesn't work at all
I know this might sound daft but is your class actually trying to log anything? - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: Log4J doesn't work at all
See http://logging.apache.org/log4j/1.2/manual.html under Default Initialization Procedure Gary On Tue, Apr 10, 2012 at 6:23 AM, tomm tommm...@gmail.com wrote: From: http://hc.apache.org/httpcomponents-client-ga/logging.html I copy pasted log4j.rootLogger=INFO, 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=DEBUG log4j.logger.org.apache.http.wire=ERROR Into a file I named log4j.properties that I put into src folder a'ka default package Didn't work at all. Then I put this in my class: System.setProperty(log4j.rootLogger, INFO, stdout); System.setProperty(log4j.appender.stdout, org.apache.log4j.ConsoleAppender); System.setProperty(log4j.appender.stdout.layout, org.apache.log4j.PatternLayout); System.setProperty(log4j.appender.stdout.layout.ConversionPattern, %5p [%c] %m%n); System.setProperty(log4j.logger.org.apache.http.client, DEBUG); System.setProperty(log4j.logger.org.apache.http, DEBUG); System.setProperty(log4j.logger.org.apache.http.wire, DEBUG); Yet it didn't work at all either. No additional output was produced. How do you make it work? ps: at: http://logging.apache.org/log4j/1.2/manual.html It's not written how to do it (empty paragraph Example Configurations and non empty yet ultimately useless Tomcat paragraph). -- E-Mail: garydgreg...@gmail.com | ggreg...@apache.org JUnit in Action, 2nd Ed: http://bit.ly/ECvg0 Spring Batch in Action: http://bit.ly/bqpbCK Blog: http://garygregory.wordpress.com Home: http://garygregory.com/ Tweet! http://twitter.com/GaryGregory http://twitter.com/GaryGregory
Re: Log4J doesn't work at all
In reply to the questions: By Michael Erskine 1. I know this might sound daft but is your class actually trying to log anything? 2. Any luck with Log4J for a simple application? 3. Are you using HttpClient at the server side under Tomcat or as a standalone client? 1. Yes it does. I use: PropertyConfigurator.configure(./src/logging/log4j.properties); And shortly after logger.debug(some test message); just to test IF the proprties file was loaded and if it was loaded correctly. Yes it was. 2. logger.debug(some test message); - works. 3. Standalone client By Gary Gregory: 1. See Default Initialization Procedure 1. Just in case I added *log4j.defaultInitOverride=true *Didn't work. Also IF the configuration file specified by me was somehow overridden, then logger.debug(some test message); wouldn't work. And it works exactly as specified with configuration file I provided. I tested it with different levels than just debug level.
Re: Log4J doesn't work at all
I did this for a test: logger.debug(some test message); // - DOES get printed. my_code_here_based_on_HttpClient; // - should produce tons of logging output logger.debug(some test message); // - DOES get printed. So why the middle part doesn't produce any output? Just to recall I am using log4j.rootLogger=DEBUG, stdout so it shouldn't matter what and why. I am really puzzled now. Why the middle part doesn't produce any output?
Re: Log4J doesn't work at all
That system property stuff only applies to commons-logging, not Log4j. Look more closely at the instructions [1]. BTW, are you using commons-logging-api.jar? If so, that's the problem. You need commons-logging.jar. See the commons-logging release notes [2]. [1] http://hc.apache.org/httpcomponents-client-ga/logging.html [2] http://commons.apache.org/logging/RELEASE-NOTES.txt Jake On Tue, 10 Apr 2012 12:23:55 +0200 tomm tommm...@gmail.com wrote: From: http://hc.apache.org/httpcomponents-client-ga/logging.html I copy pasted log4j.rootLogger=INFO, 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=DEBUG log4j.logger.org.apache.http.wire=ERROR Into a file I named log4j.properties that I put into src folder a'ka default package Didn't work at all. Then I put this in my class: System.setProperty(log4j.rootLogger, INFO, stdout); System.setProperty(log4j.appender.stdout, org.apache.log4j.ConsoleAppender); System.setProperty(log4j.appender.stdout.layout, org.apache.log4j.PatternLayout); System.setProperty(log4j.appender.stdout.layout.ConversionPattern, %5p [%c] %m%n); System.setProperty(log4j.logger.org.apache.http.client, DEBUG); System.setProperty(log4j.logger.org.apache.http, DEBUG); System.setProperty(log4j.logger.org.apache.http.wire, DEBUG); Yet it didn't work at all either. No additional output was produced. How do you make it work? ps: at: http://logging.apache.org/log4j/1.2/manual.html It's not written how to do it (empty paragraph Example Configurations and non empty yet ultimately useless Tomcat paragraph). - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: Log4J doesn't work at all
On 10 April 2012 15:34, Jacob Kjome h...@visi.com wrote: That system property stuff only applies to commons-logging, not Log4j. Look more closely at the instructions [1]. BTW, are you using commons-logging-api.jar? If so, that's the problem. You need commons-logging.jar. See the commons-logging release notes [2]. [1] http://hc.apache.org/**httpcomponents-client-ga/**logging.htmlhttp://hc.apache.org/httpcomponents-client-ga/logging.html [2] http://commons.apache.org/**logging/RELEASE-NOTES.txthttp://commons.apache.org/logging/RELEASE-NOTES.txt Jake But I don't want to use commons-logging. I want to use log4j. In any case, that System.property stuff didn't help either. Part of the code simply gets. ignored. Why?
Re: Log4J doesn't work at all
But I don't want to use commons-logging. I want to use log4j. You are missing the point. **You** want to use Log4j. That's fine. But HttpClient doesn't directly use Log4j. It directly uses commons-logging, which is a Logger adapter that supports various logging implementations, one of which is Log4j. If you want to use Log4j, then you ***have*** to use commons-logging.jar, and NOT commons-logging-api.jar, plus log4j.jar. To avoid commons-logging (and some of the problems it can create), you can skip commons-logging.jar and use SLF4J [1]: jcl-over-slf4j.jar + slf4j-api.jar + slf4j-log4j12.jar + log4j.jar. But either way, you can't avoid having the commons-logging packages/classes (which jcl-over-slf4j.jar mimics) in the classpath because HttpClient has a hard dependency on it. In any case, that System.property stuff didn't help either. Because it's commons-logging specific and totally irrelevant to Log4j. Besides, you were setting Log4j packages as properties and that is totally meaningless. For instance, you wrote... System.setProperty(log4j.logger.org.apache.http.client, DEBUG); But HttpClient's instructions say to do (again, read the instructions more closely)... System.setProperty(org.apache.commons.logging.simplelog.log.org.apache.http.wire, DEBUG); Part of the code simply gets. ignored. Why? Because you are not following instructions. [1] http://slf4j.org/legacy.html#jcl-over-slf4j Jake On Tue, 10 Apr 2012 16:08:07 +0200 tomm tommm...@gmail.com wrote: On 10 April 2012 15:34, Jacob Kjome h...@visi.com wrote: That system property stuff only applies to commons-logging, not Log4j. Look more closely at the instructions [1]. BTW, are you using commons-logging-api.jar? If so, that's the problem. You need commons-logging.jar. See the commons-logging release notes [2]. [1] http://hc.apache.org/**httpcomponents-client-ga/**logging.htmlhttp://hc.apache.org/httpcomponents-client-ga/logging.html [2] http://commons.apache.org/**logging/RELEASE-NOTES.txthttp://commons.apache.org/logging/RELEASE-NOTES.txt Jake But I don't want to use commons-logging. I want to use log4j. In any case, that System.property stuff didn't help either. Part of the code simply gets. ignored. Why? - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: Log4J doesn't work at all
There is no commons-logging-api.jar in my classpath anywhere. There is commons-logging-1.1.1.jar (there are 2 of them actually). There is only one log4j in my classpath and it is log4j-1.2.16.jar I highly doubt a problem to be a classpath problem, because then the logger.debug(some test message); would produce nothing, and it works well. Tom
Re: Log4J doesn't work at all
System.setProperty(log4j.**logger.org.apache.http.client**, DEBUG); But HttpClient's instructions say to do (again, read the instructions more closely)... System.setProperty(org.**apache.commons.logging.** simplelog.log.org.apache.http.**wire, DEBUG); For the record, you are refering to HttpClient 3.x HttpClient 3.x logging works perfectly for me, straight off the bat. HttpClient 4.x doesn't work at all. And it has different syntax. Just for the sake of it - I used old syntax with new HttpClient - no output generated. Tom
Re: Log4J doesn't work at all
On Tue, 10 Apr 2012 18:43:21 +0200 tomm tommm...@gmail.com wrote: There is no commons-logging-api.jar in my classpath anywhere. There is commons-logging-1.1.1.jar (there are 2 of them actually). There is only one log4j in my classpath and it is log4j-1.2.16.jar Are the jars binary identical? That is, are they exactly the same size with exactly the same contents? What size are they? 52k would indicate it is the API jar (bad) by another name, 60k would indicate it really is the complete commons-logging.jar (good). Why do you have two of them on the classpath anyway? Are you running on the command line or under an App Server like Tomcat? If under an app server (provide name/version), do you put all your lib dependencies, including log4j.jar and commons-logging.jar, in WEB-INF/lib or elsewhere? If elsewhere, please detail. I highly doubt a problem to be a classpath problem, because then the logger.debug(some test message); would produce nothing, and it works well. That you can log directly to Log4j is good, but is of no consequence as it relates to HttpClient logging. The cause of your issue is almost certainly commons-logging, not Log4j, because HttpClient logs directly to commons-logging. It is the job of commons-logging to direct this logging to Log4j which it is, apparently, failing to do. The reason I need you to verify that you are not, in fact, using the commons-logging API jar is that it has no Log4j binding and, thus, would explain the lack of Log4j output. If you are, indeed, using the complete commons-logging.jar, containing Log4j bindings, then we need to look for other causes. And, BTW, these things are almost **always** classpath/classloading issues. Tom Jake - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: Log4J doesn't work at all
On Tue, 10 Apr 2012 19:23:18 +0200 tomm tommm...@gmail.com wrote: System.setProperty(log4j.**logger.org.apache.http.client**, DEBUG); But HttpClient's instructions say to do (again, read the instructions more closely)... System.setProperty(org.**apache.commons.logging.** simplelog.log.org.apache.http.**wire, DEBUG); For the record, you are refering to HttpClient 3.x HttpClient 3.x logging works perfectly for me, straight off the bat. I'm referring to the page you provided which provides instructions, of which the only ones that have anything to do with setting system properties to configure logging are the commons-logging examples [1]. In fact, I see no mention of version 3.x. The page appears to be exclusively for 4.x. If this is wrong, then file a bug with the HttpComponents project. HttpClient 4.x doesn't work at all. And it has different syntax. Just for the sake of it - I used old syntax with new HttpClient - no output generated. What old syntax? The syntax documented on the page? Again, if that's old, then file a bug with HttpComponents. In any case, clearly Log4j generally works for you, since it works when you log directly as well as with HttpClient-3.x. The difference appears to be the HttpClient version. Therefore, I suggest you ask the HttpClient developers. I'm not sure what else to tell you? Tom [1] http://hc.apache.org/httpcomponents-client-ga/logging.html#Commons_Logging_Examples Jake - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: Log4J doesn't work at all
On 10 April 2012 19:25, Jacob Kjome h...@visi.com wrote: On Tue, 10 Apr 2012 18:43:21 +0200 Are the jars binary identical? That is, are they exactly the same size with exactly the same contents? One is 60.7 KB and one is 60.8 KB What size are they? 52k would indicate it is the API jar (bad) by another name, 60k would indicate it really is the complete commons-logging.jar (good). Why do you have two of them on the classpath anyway? Because when I add a jar that has it's own dependencies I add it via Tools - Libraries - Add new. This way my project (right click) - Properties - Libraries looks way cleaner. It only shows main jars and not absolutely all jars. Are you running on the command line or under an App Server like Tomcat? If under an app server (provide name/version), do you put all your lib dependencies, including log4j.jar and commons-logging.jar, in WEB-INF/lib or elsewhere? If elsewhere, please detail. Running command line. From within NetBeans. No fancy stuff. That you can log directly to Log4j is good, but is of no consequence as it relates to HttpClient logging. The cause of your issue is almost certainly commons-logging, not Log4j, because HttpClient logs directly to commons-logging. It is the job of commons-logging to direct this logging to Log4j which it is, apparently, failing to do. The reason I need you to verify that you are not, in fact, using the commons-logging API jar is that it has no Log4j binding and, thus, would explain the lack of Log4j output. If you are, indeed, using the complete commons-logging.jar, containing Log4j bindings, then we need to look for other causes. And, BTW, these things are almost **always** classpath/classloading issues As far as classloading goes, on the libraries list, I put log4j at the top and HttpClient right after it. The other jar that was using commons-logging ('pbapi.jar' - unrelated) I put on bottom. I will try to download commons-logging from main website and point HttpClient to it manually.
Re: Log4J doesn't work at all
My debug for log4j: log4j: Trying to find [log4j.xml] using context classloader sun.misc.Launcher$AppClassLoader@56e88e24. log4j: Trying to find [log4j.xml] using sun.misc.Launcher$AppClassLoader@56e88e24 class loader. log4j: Trying to find [log4j.xml] using ClassLoader.getSystemResource(). log4j: Trying to find [log4j.properties] using context classloader sun.misc.Launcher$AppClassLoader@56e88e24. log4j: Trying to find [log4j.properties] using sun.misc.Launcher$AppClassLoader@56e88e24 class loader. log4j: Trying to find [log4j.properties] using ClassLoader.getSystemResource(). log4j: Could not find resource: [null]. log4j: Parsing for [root] with value=[DEBUG, stdout]. log4j: Level token is [DEBUG]. log4j: Category root set to DEBUG log4j: Parsing appender named stdout. log4j: Parsing layout options for stdout. log4j: Setting property [conversionPattern] to [%5p [%c] %m%n]. log4j: End of parsing for stdout. log4j: Parsed stdout options. log4j: Parsing for [org.apache.http.wire] with value=[DEBUG]. log4j: Level token is [DEBUG]. log4j: Category org.apache.http.wire set to DEBUG 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: Parsing for [jobManager] with value=[DEBUG]. log4j: Level token is [DEBUG]. log4j: Category jobManager set to DEBUG log4j: Handling log4j.additivity.jobManager=[null] log4j: Finished configuring. My output for System.out.println(httpClient.getClass().getClassLoader().getResource(log4j.properties)); is: null It seems the httpClient is not using the logger properties I specified. But I thought that's why there was this line: log4j.logger.org.apache.http=DEBUG in the first place. I am so confused. Any hints?
Re: Log4J doesn't work at all
In your other email you say... Running command line. From within NetBeans. No fancy stuff. Never discount the complexity of an IDE and how it forks JVMs and/or performs idiosyncratic classloading. In any case, your test below is invalid in this context. You claimed, in an earlier response, that you load your config manually using... PropertyConfigurator.configure(./src/logging/log4j.properties); The output you see from Log4j, ending with the line... log4j: Could not find resource: [null]. ...just means that Log4j default config lookup didn't find a Log4j config file in the root of the classpath. That's normal if you didn't put it there. But because you manually configure, your config is loaded, so you can ignore the above line. The one odd thing I see is that there is a logger named jobManager that is configured. I don't see that in the log4 config you posted in a previous response (see below). Are you sure the config file that is being loaded is the one you **think** is being loaded? I copy pasted log4j.rootLogger=INFO, 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=DEBUG log4j.logger.org.apache.http.wire=ERROR Into a file I named log4j.properties that I put into src folder a'ka default package BTW, why do you configure a properties file from a src folder. Why not just copy that into some folder on the classpath and let Log4j auto-configure. Besides, your methodology of using... PropertyConfigurator.configure(./src/logging/log4j.properties); ...suffers from the fact that this is a file path, relative to the directory from which the JVM started. That is bound to change from environment to environment and, therefore, brittle. Just stick it in the classpath and let Log4j pick it up. Jake On Tue, 10 Apr 2012 21:29:51 +0200 tomm tommm...@gmail.com wrote: My debug for log4j: log4j: Trying to find [log4j.xml] using context classloader sun.misc.Launcher$AppClassLoader@56e88e24. log4j: Trying to find [log4j.xml] using sun.misc.Launcher$AppClassLoader@56e88e24 class loader. log4j: Trying to find [log4j.xml] using ClassLoader.getSystemResource(). log4j: Trying to find [log4j.properties] using context classloader sun.misc.Launcher$AppClassLoader@56e88e24. log4j: Trying to find [log4j.properties] using sun.misc.Launcher$AppClassLoader@56e88e24 class loader. log4j: Trying to find [log4j.properties] using ClassLoader.getSystemResource(). log4j: Could not find resource: [null]. log4j: Parsing for [root] with value=[DEBUG, stdout]. log4j: Level token is [DEBUG]. log4j: Category root set to DEBUG log4j: Parsing appender named stdout. log4j: Parsing layout options for stdout. log4j: Setting property [conversionPattern] to [%5p [%c] %m%n]. log4j: End of parsing for stdout. log4j: Parsed stdout options. log4j: Parsing for [org.apache.http.wire] with value=[DEBUG]. log4j: Level token is [DEBUG]. log4j: Category org.apache.http.wire set to DEBUG 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: Parsing for [jobManager] with value=[DEBUG]. log4j: Level token is [DEBUG]. log4j: Category jobManager set to DEBUG log4j: Handling log4j.additivity.jobManager=[null] log4j: Finished configuring. My output for System.out.println(httpClient.getClass().getClassLoader().getResource(log4j.properties)); is: null It seems the httpClient is not using the logger properties I specified. But I thought that's why there was this line: log4j.logger.org.apache.http=DEBUG in the first place. I am so confused. Any hints? - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: Log4J doesn't work at all
On 10 April 2012 22:30, Jacob Kjome h...@visi.com wrote: In your other email you say... Running command line. From within NetBeans. No fancy stuff. Never discount the complexity of an IDE and how it forks JVMs and/or performs idiosyncratic classloading. I load/run only 1 JVM at a time. 1 Thread I might add. No forking here. In any case, your test below is invalid in this context. You claimed, in an earlier response, that you load your config manually using... PropertyConfigurator.**configure(./src/logging/**log4j.properties); The output you see from Log4j, ending with the line... log4j: Could not find resource: [null]. As the log4j debug stays, the file is being found and loaded after all. ...just means that Log4j default config lookup didn't find a Log4j config file in the root of the classpath. That's normal if you didn't put it there. But because you manually configure, your config is loaded, so you can ignore the above line. The one odd thing I see is that there is a logger named jobManager that is configured. I don't see that in the log4 config you posted in a previous response (see below). Are you sure the config file that is being loaded is the one you **think** is being loaded? First, I have to make it work. I can always add an entry in proprties file for a specific class later on. First it must work - then I will worry about details. I copy pasted log4j.rootLogger=INFO, 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=**DEBUG log4j.logger.org.apache.http.**wire=ERROR Into a file I named log4j.properties that I put into src folder a'ka default package BTW, why do you configure a properties file from a src folder. Why not just copy that into some folder on the classpath and let Log4j auto-configure. Besides, your methodology of using... PropertyConfigurator.**configure(./src/logging/**log4j.properties); ...suffers from the fact that this is a file path, relative to the directory from which the JVM started. Alright. It will change. But it's on my super bottom list of worries. I first have to make it work. Then worry about the rest. That is bound to change from environment to environment and, therefore, brittle. Just stick it in the classpath and let Log4j pick it up. Has been already done sir ^^ Didn't help :( Jake :(
Re: Log4J doesn't work at all
tomm tommm...@gmail.com wrote on 04/10/2012 05:06:20 PM: The one odd thing I see is that there is a logger named jobManager that is configured. I don't see that in the log4 config you posted in a previous response (see below). Are you sure the config file that is being loaded is the one you **think** is being loaded? First, I have to make it work. I can always add an entry in proprties file for a specific class later on. First it must work - then I will worry about details. the log4j properties that you originally posted has nothing in it about jobManager; the output indicates that the one getting used does have settings for jobManager. Jacob has asked a question that may or may not be salient: are you sure the config file that is being loaded is the one you **think** is being loaded, or has the log4j.properties morphed along the way, and the file getting used is indeed the one that think is being used? 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?