You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by nc...@apache.org on 2016/11/08 20:25:21 UTC
[13/22] ambari git commit: AMBARI-18592. Ability to enable the
DEBUG/INFO logs in Ambari-server without server restart (Amarnath Reddy Pappu
via alejandro)
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/3ec7df13
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/3ec7df13
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/3ec7df13
Branch: refs/heads/branch-feature-AMBARI-18634
Commit: 3ec7df13485b629bcf08310f3916b6401f827dbe
Parents: 922f87a
Author: Alejandro Fernandez <af...@hortonworks.com>
Authored: Mon Nov 7 14:04:11 2016 -0800
Committer: Alejandro Fernandez <af...@hortonworks.com>
Committed: Mon Nov 7 14:04:11 2016 -0800
----------------------------------------------------------------------
.../server/configuration/Configuration.java | 8 +++++++
.../ambari/server/controller/AmbariServer.java | 23 ++++++++++++++++++++
2 files changed, 31 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/3ec7df13/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 2ce247c..3103b6d 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
@@ -2449,6 +2449,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);
@@ -2625,6 +2632,7 @@ public class Configuration {
configsMap.put(PARALLEL_STAGE_EXECUTION.getKey(), getProperty(PARALLEL_STAGE_EXECUTION));
configsMap.put(SERVER_TMP_DIR.getKey(), getProperty(SERVER_TMP_DIR));
configsMap.put(REQUEST_LOGPATH.getKey(), getProperty(REQUEST_LOGPATH));
+ configsMap.put(LOG4JMONITOR_DELAY.getKey(), getProperty(LOG4JMONITOR_DELAY));
configsMap.put(REQUEST_LOG_RETAINDAYS.getKey(), getProperty(REQUEST_LOG_RETAINDAYS));
configsMap.put(EXTERNAL_SCRIPT_TIMEOUT.getKey(), getProperty(EXTERNAL_SCRIPT_TIMEOUT));
configsMap.put(SHARED_RESOURCES_DIR.getKey(), getProperty(SHARED_RESOURCES_DIR));
http://git-wip-us.apache.org/repos/asf/ambari/blob/3ec7df13/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 7677c07..6351720 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
@@ -124,6 +124,7 @@ 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.Handler;
import org.eclipse.jetty.server.NCSARequestLog;
@@ -504,6 +505,8 @@ public class AmbariServer {
//Check and load requestlog handler.
loadRequestlogHandler(handlerList, serverForAgent, configsMap);
+ enableLog4jMonitor(configsMap);
+
handlerList.addHandler(root);
server.setHandler(handlerList);
@@ -977,6 +980,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);
+ }
+ }
+
+ /**
* For loading requestlog handlers
*/
private static void loadRequestlogHandler(AmbariHandlerList handlerList, Server serverForAgent , Map<String, String> configsMap) {