You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by sm...@apache.org on 2015/06/15 23:04:49 UTC
ambari git commit: AMBARI-9409. Configure Ambari-agent logging - add
syslog handler (Chelsey Chang via smohanty)
Repository: ambari
Updated Branches:
refs/heads/trunk 76499d9cd -> 93f611577
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/93f61157
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/93f61157
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/93f61157
Branch: refs/heads/trunk
Commit: 93f61157745d71e03f02b2b307f30848fe18c717
Parents: 76499d9
Author: Sumit Mohanty <sm...@hortonworks.com>
Authored: Mon Jun 15 14:04:37 2015 -0700
Committer: Sumit Mohanty <sm...@hortonworks.com>
Committed: Mon Jun 15 14:04:37 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/93f61157/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/93f61157/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