I don't change the logging config in code so I am not familiar with
that but you should only have to change the level of loggers with an
appender attached (at most).
On 10/12/06, vincentw <[EMAIL PROTECTED]> wrote:
Its seems the new level doesn't take effect. So here's what I'm trying to
do. I call a function "initLogging" to set up everything...call
DOMConfigurator and pass it my log4j.xml file. So now log4j is setup with
some default stuff. Now the cofig file may change the settings ie. logging
level.
Here's part of the code that does a check for config file
...
if(useUserConfigFile)
{
aLogger.setMaxBackupIndex(zxConfig.getProperty("numLogs"));
aLogger.setMaxFileSize(Long.parseLong(zxConfi.getProperty("logSize")));
a.setLoggingLevel("root", zxConfig.getProperty("rootLogLevel"));
a.setLoggingLevel("sql.xxx.xxx", zxConfig.getProperty("sqlLogLevel"));
}
Here is part of the code to set the new logging...
...
Enumeration enLogger =
Logger.getRootLogger().getLoggerRepository().getCurrentLoggers();
Logger tmpLogger = null;
/* If logger is root, then need to loop through all loggers under root
* and change their logging levels too. Also, skip sql loggers so
they
* do not get effected.
*/
while(enLogger.hasMoreElements())
{
tmpLogger = (Logger)(enLogger.nextElement());
if(tmpLogger.getName().startsWith("sql.xxx.xxx") &&
logger.equals("sql.xxx.xxxi"))
{
tmpLogger.setLevel(Level.toLevel(level));
continue;
}
if(tmpLogger.getName().startsWith("xxx.xx") &&
logger.equals("root"))
{
tmpLogger.setLevel(Level.toLevel(level));
}
}
while(enAppenders.hasMoreElements())
{
appender = (Appender)enAppenders.nextElement();
if(appender.getName().equals("ASYNC"))
{
AsyncAppender asyncAppender = (AsyncAppender)appender;
rfa = (RollingFileAppender)asyncAppender.getAppender("R");
rfa.activateOptions();
ca = (ConsoleAppender)asyncAppender.getAppender("STDOUT");
ca.activateOptions();
}
}
Another question is, at this point, I have use getLogger for a lot of
packages. Now I want to change to logging level of my root package, and
everything under it. I need to loop through all loggers like I have in the
code right?
Or is there a better way of doing this?
Thanks
--
View this message in context:
http://www.nabble.com/Can-I-change-log4j-configuration-programatically--tf2420301.html#a6784793
Sent from the Log4j - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
James Stauffer http://www.geocities.com/stauffer_james/
Are you good? Take the test at http://www.livingwaters.com/good/
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]