I want to use multiple instances of the log4j Logger. I need to attach different Properties objects to each of these log4j Logger instances.
Here is the code to configure for one instance:
LOG4J = org.apache.log4j.Logger.getLogger(Logger.class);
Properties log4jProps = new Properties();
...
PropertyConfigurator.configure(log4jProps);
What if I want to have two log4j instance and each of them has different properties?
Can you explain why you want multiple loggers in more detail? I don't think it's possible to have multiple log4j instances.
If you just want multiple appenders, look here:
Here's the log4j.properties from the above link:
These lines:
say the following:
It's also possible to supply full class names:
means log everything from
com.lewscanon.SomeClass
class to appender F, level warn and above.I suppose the above is granular enough, but if you absolutely need it more granular (I don't think that's practical enough, though), per:
Logger.getLogger(String name)
accepts names. So you can do something like:and use
Logger.getLogger("myFancyLogger")
to get the logger that logs to appender F with level info.