Programmatically configuring Log4J Logger while leaving config alone
Ok, this may be some lack of understanding of log4j on my part, but what is a programmatic way to configure a specific log4j logger without affecting the root logger or other loggers/appenders?
Here is the goal here: I have an app that has plenty of commons-logging/log4j stuff spread throughout the code in a traditional way. These are configured via log4j.properties and I am generally happy with what they do. I would like to add to this a separate logger to act as a "Console" logger in the sense that this is the main output of the app and I would like to control the format and log level and appenders from the command line options WITHOUT affecting the general setup of the log4j for other uses. Traditionally I used my own helper class that used System.out.print and did my own thresholding and formatting, but given that I already have log4j in there, it seems silly to do so.
What I tried to do is extend Logger class with some helper methods that allow me to configure the specific logger. But looking at the "extend Logger" example in the log4j docs, it seems that in order to configure appenders programatically I need to add the new appenders to the Root logger, and not to the actual logger. This works, but also affects all other loggers - which is not my intent. Is there a way add appender to a specific logger without adding it to Root logger? When I try this, I get no output at all from ANY of the loggers. I suspect I loose the configuration when I do this, but not sure why. Running with log4j.debug=true shows the config file loaded but nothing after that :-(