Results 1 to 1 of 1
- 05-19-2010, 09:44 PM #1Member
- Join Date
- Oct 2008
- Rep Power
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 :-(
- By rameshraj in forum JDBCReplies: 5Last Post: 03-17-2011, 02:26 PM
- By vintem in forum New To JavaReplies: 0Last Post: 05-13-2010, 07:03 PM
- By Anny_1985 in forum Web FrameworksReplies: 0Last Post: 07-24-2009, 01:18 PM
- By shivakumari in forum Java ServletReplies: 3Last Post: 03-25-2009, 06:25 AM
- By Marcus in forum Advanced JavaReplies: 1Last Post: 07-06-2007, 04:06 PM