Support for root logger level runtime update

Closes: #2517
This commit is contained in:
uboness 2013-01-03 01:23:40 +01:00
parent 6c4108b38a
commit 9f60dc7578
5 changed files with 31 additions and 1 deletions

View File

@ -66,9 +66,15 @@ public abstract class ESLoggerFactory {
return defaultFactory.newInstance(name.intern());
}
public static ESLogger getRootLogger() {
return defaultFactory.rootLogger();
}
public ESLogger newInstance(String name) {
return newInstance(null, name);
}
protected abstract ESLogger rootLogger();
protected abstract ESLogger newInstance(String prefix, String name);
}

View File

@ -22,11 +22,18 @@ package org.elasticsearch.common.logging.jdk;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.ESLoggerFactory;
import java.util.logging.LogManager;
/**
*
*/
public class JdkESLoggerFactory extends ESLoggerFactory {
@Override
protected ESLogger rootLogger() {
return getLogger("");
}
@Override
protected ESLogger newInstance(String prefix, String name) {
final java.util.logging.Logger logger = java.util.logging.Logger.getLogger(name);

View File

@ -19,6 +19,8 @@
package org.elasticsearch.common.logging.log4j;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.ESLoggerFactory;
@ -27,6 +29,11 @@ import org.elasticsearch.common.logging.ESLoggerFactory;
*/
public class Log4jESLoggerFactory extends ESLoggerFactory {
@Override
protected ESLogger rootLogger() {
return new Log4jESLogger(null, Logger.getRootLogger());
}
@Override
protected ESLogger newInstance(String prefix, String name) {
final org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(name);

View File

@ -21,6 +21,7 @@ package org.elasticsearch.common.logging.slf4j;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.ESLoggerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
@ -28,6 +29,11 @@ import org.slf4j.LoggerFactory;
*/
public class Slf4jESLoggerFactory extends ESLoggerFactory {
@Override
protected ESLogger rootLogger() {
return getLogger(Logger.ROOT_LOGGER_NAME);
}
@Override
protected ESLogger newInstance(String prefix, String name) {
return new Slf4jESLogger(prefix, LoggerFactory.getLogger(name));

View File

@ -79,9 +79,13 @@ public class NodeSettingsService extends AbstractComponent implements ClusterSta
for (Map.Entry<String, String> entry : event.state().metaData().settings().getAsMap().entrySet()) {
if (entry.getKey().startsWith("logger.")) {
String component = entry.getKey().substring("logger.".length());
if ("_root".equals(component)) {
ESLoggerFactory.getRootLogger().setLevel(entry.getValue());
} else {
ESLoggerFactory.getLogger(component).setLevel(entry.getValue());
}
}
}
} catch (Exception e) {
logger.warn("failed to refresh settings for [{}]", e, "logger");
}