Results 1 to 1 of 1
- 05-19-2010, 10: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, 03:26 PM
- By vintem in forum New To JavaReplies: 0Last Post: 05-13-2010, 08:03 PM
- By Anny_1985 in forum Web FrameworksReplies: 0Last Post: 07-24-2009, 02:18 PM
- By shivakumari in forum Java ServletReplies: 3Last Post: 03-25-2009, 07:25 AM
- By Marcus in forum Advanced JavaReplies: 1Last Post: 07-06-2007, 05:06 PM