How can I stop the Apache debug log4j log statements but still use framework?
I am not clear if I put in log4j.rootlogger=OFF do I have to put in the properties file a
and then from within the each object I want to log do I do:
Logger aaa = Logger.getLogger(aaa.class)
and then just use api from there? That would be elegant, if not in understanding, grin.
David Newton wrote:I"m not sure what you're asking.
I appear to groping my way through.
I cant use the std configuration of l4j, b/c all of the debug code for apache ...digester & digester.sax shows. I thought I could disable it with log4j.rootlogger=OFF and configure my own withing the individual object, loosing elegant runtime configuration, but at least it would work.
I am still seeing the org.apache.commons.digester.Digester, and all the parsing of the struts configuration files. However my technique did work and I am getting log lines from my individually configured objects.
My questions are two
1. How can I stop debug from Apache without setting a higher leve on the root logger? I want to use debug level in my code.
2. Is there a configuration which which I can have runtime configuration of my object specific loggers? What is the syntax to configure them from the log4j.properties file specific for each object's class name AND how do I access them from within the specific object class?
This is the configuration is /src
# Set root logger level to DEBUG and its only appender to A1.
# A1 is set to be a ConsoleAppender.
If you set the rootlogger to DEBUG sure, you're going to get mass quantities of debug log messages.
You can turn specific packages on/off by configuring individual loggers for them.
Personally I usually just set the root logger to INFO or WARN and set *my* packages to DEBUG. I don't find anything particularly elegant about runtime configuration, and it's a rare occasion I ever do anything more interesting with my Log instances than just create class-specific loggers.
Joined: Aug 27, 2005
Thanks. But I thought I set the root to OFF, if that is even a command, that I "picked" up ad hoc on some google search.
The reason I find runtime configuration elegant is I have many objects, and now as I understand it I am configuring them in the constructor of each object, and setting their logging level. This means, as I understand it, that if I want to simulate production I have to go to each object and set its level to something high. This requires a source edit and recompile. I would like to just do it from the configuration file. And this is b/c the apache code has taken over the DEBUG level with its line. Yes, I am sure I could recompile it, but I prefer to buy my groceries and pasta vbg.
If that is possible, what is the syntax to create those object specific debuggers in the log4j.properties AND what is the calling syntax in the object specific code to set the logging information?
If I understand correctly, you are setting the levels programmatically within the code?
Then of course you need to change it every time you wan tto change the logging behavior. Why are you doing that? The whole point of Log4J is to set up the logging and then be able to control it completely from configuration without the need for code changes.
In general you'll see configuration like this:This means that everything not explicitly defined has a log level of WARN: the app will be relatively quiet. However I've explicitly configured several high-level packages: I'll get lots of log messages from things in the com.davenewton.foo and org.apache.struts2 packages, almost nothing from ognl, and INFO msgs from com.opensymphony.xwork2.
In the Java code itself logs are defined like this:To make that log message not appear I simply change the com.davenewton.foo package's log level to, for example, INFO--in the log4j.properties file.
Maybe if you showed some of your code and/or explained what you're trying to do we'd understand the problem more clearly.