Repository: ambari Updated Branches: refs/heads/branch-2.5 fc8a56e02 -> dce90ea23
AMBARI-18592. Ability to enable the DEBUG/INFO logs in Ambari-server without server restart (Amarnath Reddy Pappu via alejandro) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/dce90ea2 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/dce90ea2 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/dce90ea2 Branch: refs/heads/branch-2.5 Commit: dce90ea23f916a8ff5275b8667b510541a74bce4 Parents: fc8a56e Author: Alejandro Fernandez <[email protected]> Authored: Mon Nov 7 14:09:29 2016 -0800 Committer: Alejandro Fernandez <[email protected]> Committed: Mon Nov 7 14:09:29 2016 -0800 ---------------------------------------------------------------------- .../server/configuration/Configuration.java | 8 +++++++ .../ambari/server/controller/AmbariServer.java | 24 ++++++++++++++++++++ 2 files changed, 32 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/dce90ea2/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java index 86c26c8..8857e19 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java @@ -2384,6 +2384,13 @@ public class Configuration { public static final ConfigurationProperty<Boolean> ACTIVE_INSTANCE = new ConfigurationProperty<>( "active.instance", Boolean.TRUE); + /** + * PropertyConfigurator checks log4j.properties file change every LOG4JMONITOR_DELAY milliseconds. + */ + @Markdown(description = "Indicates the delay, in milliseconds, for the log4j monitor to check for changes") + public static final ConfigurationProperty<Long> LOG4JMONITOR_DELAY = new ConfigurationProperty<>( + "log4j.monitor.delay", TimeUnit.MINUTES.toMillis(5)); + private static final Logger LOG = LoggerFactory.getLogger( Configuration.class); @@ -2693,6 +2700,7 @@ public class Configuration { configsMap.put(JAVA_HOME.getKey(), getProperty(JAVA_HOME)); configsMap.put(PARALLEL_STAGE_EXECUTION.getKey(), getProperty(PARALLEL_STAGE_EXECUTION)); configsMap.put(SERVER_TMP_DIR.getKey(), getProperty(SERVER_TMP_DIR)); + configsMap.put(LOG4JMONITOR_DELAY.getKey(), getProperty(LOG4JMONITOR_DELAY)); configsMap.put(EXTERNAL_SCRIPT_TIMEOUT.getKey(), getProperty(EXTERNAL_SCRIPT_TIMEOUT)); configsMap.put(SHARED_RESOURCES_DIR.getKey(), getProperty(SHARED_RESOURCES_DIR)); configsMap.put(KDC_PORT.getKey(), getProperty(KDC_PORT)); http://git-wip-us.apache.org/repos/asf/ambari/blob/dce90ea2/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java index 99203bd..ce3fe85 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java @@ -120,6 +120,8 @@ import org.apache.ambari.server.view.AmbariViewsMDCLoggingFilter; import org.apache.ambari.server.view.ViewDirectoryWatcher; import org.apache.ambari.server.view.ViewRegistry; import org.apache.ambari.server.view.ViewThrottleFilter; +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.PropertyConfigurator; import org.apache.velocity.app.Velocity; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.SessionIdManager; @@ -492,6 +494,8 @@ public class AmbariServer { viewRegistry.readViewArchives(); viewDirectoryWatcher.start(); + enableLog4jMonitor(configsMap); + handlerList.addHandler(root); server.setHandler(handlerList); @@ -939,6 +943,26 @@ public class AmbariServer { } } + /** + * To change log level without restart. + */ + public static void enableLog4jMonitor(Map<String, String> configsMap){ + + String log4jpath = AmbariServer.class.getResource("/"+Configuration.AMBARI_LOG_FILE).toString(); + String monitorDelay = configsMap.get(Configuration.LOG4JMONITOR_DELAY.getKey()); + long monitorDelayLong = Configuration.LOG4JMONITOR_DELAY.getDefaultValue(); + + try{ + log4jpath = log4jpath.replace("file:", ""); + if(StringUtils.isNotBlank(monitorDelay)) { + monitorDelayLong = Long.parseLong(monitorDelay); + } + PropertyConfigurator.configureAndWatch(log4jpath, monitorDelayLong); + }catch(Exception e){ + LOG.error("Exception in setting log4j monitor delay of {} for {}", monitorDelay, log4jpath, e); + } + } + public static void main(String[] args) throws Exception { Injector injector = Guice.createInjector(new ControllerModule(), new AuditLoggerModule());
