| Author |
log4j question
|
Samuel Mendenhall
Greenhorn
Joined: Oct 17, 2004
Posts: 18
|
|
I am implementing log4j for the first time. I have a question about how it works. If I set the logging level in my properties file to DEBUG,then I get a way too indepth view of my code, every single thing that gets called gets output to the console. What I want is this. I want to set my logging to DEBUG, and only get the DEBUG statements that I specify, like logger.debug("debugging statement"), instead of getting all of this information I don't want at the moment. Is there another property to set so log4j only outputs based on my logging statements that I write? Here is my properties file log4j.rootLogger=INFO, stdout, R log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout # Pattern to output the caller's file name and line number. log4j.appender.stdout.layout.ConversionPattern=[%p] [%F : %M : %L] - %m%n log4j.appender.R=org.apache.log4j.RollingFileAppender log4j.appender.R.File=example.log log4j.appender.R.MaxFileSize=100KB # Keep one backup file log4j.appender.R.MaxBackupIndex=1 log4j.appender.R.layout=org.apache.log4j.PatternLayout log4j.appender.R.layout.ConversionPattern=%%5p (%F:%M:%L) - %m%n
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 13842
|
|
Is there another property to set so log4j only outputs based on my logging statements that I write?
Well, no, because log4j doesn't do any output based on logging statements that you didn't write. So you must have meant something else here. Do you have one class of logger.debug() calls that you want to see and another class of logger.debug() calls that you don't want to see? Or what?
|
 |
Samuel Mendenhall
Greenhorn
Joined: Oct 17, 2004
Posts: 18
|
|
Here a snippet of the output I'm seeing. And I'm definitely not logging any of this via logger.debug("..."). [DEBUG] [HttpMethodBase.java-writeRequest-1916] - enter HttpMethodBase.writeRequest(HttpState, HttpConnection) [DEBUG] [HttpConnection.java-print-1026] - enter HttpConnection.print(String) [DEBUG] [HttpConnection.java-write-936] - enter HttpConnection.write(byte[]) [DEBUG] [HttpConnection.java-write-957] - enter HttpConnection.write(byte[], int, int)
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 13842
|
|
So something else in your JVM is doing that logging. Are you by chance asking this in the context of a servlet? If so, then put your log4j.properties file in your web application's classpath and not in the general classpath of your web application server. Or is this some other software that you're calling?
|
 |
Samuel Mendenhall
Greenhorn
Joined: Oct 17, 2004
Posts: 18
|
|
I am running a regular java app, no tomcat or servlets. I am getting the log4j logger by, private static Logger logger = Logger.getLogger(ClassName.class.getName()); then just doing a logger.info() or logger.debug() Where in the world could all the extra debug statements be coming from
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 13842
|
|
|
They are coming from something that's working with HTTP connections in some way. And that something, whatever it is, does debug logging via log4j. You must be calling that somehow.
|
 |
Samuel Mendenhall
Greenhorn
Joined: Oct 17, 2004
Posts: 18
|
|
|
Ahhh, you are right, I am using HTTPClient from Apache, and I'd bet for sure it is using log4j. I will try to figure out how to set up an ignore for the org.apache category/domain. Will update later if that works.
|
 |
 |
|
|
subject: log4j question
|
|
|