Hi all,
I'm probably being blind but I have a customer Logger implementation (MyLogger
extends Logger) and a custom LoggerFactory (MyLoggerFactory implements
LoggerFactory).
Properties props = new Properties();
props.put(PropertyConfigurator.LOGGER_FACTORY_KEY, "com.xxx.MyLoggerFactory");
props.put("log4j.rootLogger", "OFF");
props.put("log4j.appender.A1", "org.apache.log4j.ConsoleAppender");
props.put("log4j.appender.A1.layout", "org.apache.log4j.PatternLayout");
props.put("log4j.appender.A1.layout.ConversionPattern", "%5p [%t] %c - %m%n");
props.put("log4j.logger.com.xxxx.MyClass, "DEBUG, A1");
PropertyConfigurator.configure(props);
Logger log = Logger.getLogger(MyClass.class);
If I set
props.put("log4j.logger.com.xxxx.MyClass, "DEBUG, A1");
with the full class name for MyClass, the log variable is an instance of
MyLogger. However, if I make the configuration more generic (e.g. package
wide) with
props.put("log4j.logger.com.xxxx, "DEBUG, A1");
I get an instance of the standard log4j Logger class.
I've run through the log4j code in the debugger and I can see what it's doing,
i.e. it's creating a MyLogger for com.xxxx and adding it to the hashtable but
then when I call Logger.getLogger(MyClass.class) it uses the default factory
and returns a standard Logger.
Am I missing something here? I want all sub-packages / classes of com.xxxx to
return a MyLogger instance.
Using log4j version 1.2.12.
Many thanks,
Dave