ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smoha...@apache.org
Subject ambari git commit: AMBARI-9409. Configure Ambari-agent logging - add syslog handler (Chelsey Chang via smohanty)
Date Mon, 15 Jun 2015 21:06:00 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.1 adb3e9b39 -> d4fd63848


AMBARI-9409. Configure Ambari-agent logging - add syslog handler (Chelsey Chang via smohanty)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/d4fd6384
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/d4fd6384
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/d4fd6384

Branch: refs/heads/branch-2.1
Commit: d4fd63848514e211e45769d3d61b999ca61ae2d1
Parents: adb3e9b
Author: Sumit Mohanty <smohanty@hortonworks.com>
Authored: Mon Jun 15 14:04:37 2015 -0700
Committer: Sumit Mohanty <smohanty@hortonworks.com>
Committed: Mon Jun 15 14:05:22 2015 -0700

----------------------------------------------------------------------
 ambari-agent/conf/unix/ambari-agent.ini         |  3 +++
 .../src/main/python/ambari_agent/main.py        | 23 ++++++++++++++++++--
 2 files changed, 24 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/d4fd6384/ambari-agent/conf/unix/ambari-agent.ini
----------------------------------------------------------------------
diff --git a/ambari-agent/conf/unix/ambari-agent.ini b/ambari-agent/conf/unix/ambari-agent.ini
index def41c6..abfde62 100644
--- a/ambari-agent/conf/unix/ambari-agent.ini
+++ b/ambari-agent/conf/unix/ambari-agent.ini
@@ -47,3 +47,6 @@ dirs=/etc/hadoop,/etc/hadoop/conf,/etc/hbase,/etc/hcatalog,/etc/hive,/etc/oozie,
   /var/log/hadoop,/var/log/zookeeper,/var/log/hbase,/var/run/templeton,/var/log/hive
 ; 0 - unlimited
 log_lines_count=300
+
+[logging]
+syslog_enabled=0
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/d4fd6384/ambari-agent/src/main/python/ambari_agent/main.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/ambari_agent/main.py b/ambari-agent/src/main/python/ambari_agent/main.py
index b8becc8..0971cbb 100644
--- a/ambari-agent/src/main/python/ambari_agent/main.py
+++ b/ambari-agent/src/main/python/ambari_agent/main.py
@@ -30,6 +30,7 @@ import time
 import platform
 import ConfigParser
 import ProcessHelper
+from logging.handlers import SysLogHandler
 from Controller import Controller
 import AmbariConfig
 from NetUtil import NetUtil
@@ -52,6 +53,9 @@ config = AmbariConfig.AmbariConfig()
 configFile = config.getConfigFile()
 two_way_ssl_property = config.TWO_WAY_SSL_PROPERTY
 
+IS_LINUX = platform.system() == "Linux"
+SYSLOG_FORMAT_STRING = ' ambari_agent - %(filename)s - [%(process)d] - %(name)s - %(levelname)s
- %(message)s'
+SYSLOG_FORMATTER = logging.Formatter(SYSLOG_FORMAT_STRING)
 
 
 def setup_logging(verbose):
@@ -59,7 +63,7 @@ def setup_logging(verbose):
   rotateLog = logging.handlers.RotatingFileHandler(AmbariConfig.AmbariConfig.getLogFile(),
"a", 10000000, 25)
   rotateLog.setFormatter(formatter)
   logger.addHandler(rotateLog)
-
+      
   if verbose:
     logging.basicConfig(format=formatstr, level=logging.DEBUG, filename=AmbariConfig.AmbariConfig.getLogFile())
     logger.setLevel(logging.DEBUG)
@@ -69,7 +73,19 @@ def setup_logging(verbose):
     logger.setLevel(logging.INFO)
     logger.info("loglevel=logging.INFO")
 
-
+def add_syslog_handler(logger):
+    
+  syslog_enabled = config.has_option("logging","syslog_enabled") and (int(config.get("logging","syslog_enabled"))
== 1)
+      
+  #add syslog handler if we are on linux and syslog is enabled in ambari config
+  if syslog_enabled and IS_LINUX:
+    logger.info("Adding syslog handler to ambari agent logger")
+    syslog_handler = SysLogHandler(address="/dev/log",
+                                   facility=SysLogHandler.LOG_LOCAL1)
+        
+    syslog_handler.setFormatter(SYSLOG_FORMATTER)
+    logger.addHandler(syslog_handler)
+    
 def update_log_level(config):
   # Setting loglevel based on config file
   global logger
@@ -234,6 +250,9 @@ def main(heartbeat_stop_callback=None):
 
   # Check for ambari configuration file.
   resolve_ambari_config()
+  
+  # Add syslog hanlder based on ambari config file
+  add_syslog_handler(logger)
 
   # Starting data cleanup daemon
   data_cleaner = None


Mime
View raw message