ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aonis...@apache.org
Subject ambari git commit: AMBARI-12564. Logging of exceptions in python code in Ambari Agent (aonishuk)
Date Tue, 28 Jul 2015 12:53:13 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.1 034182622 -> bb879dbc7


AMBARI-12564. Logging of exceptions in python code in Ambari Agent (aonishuk)


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

Branch: refs/heads/branch-2.1
Commit: bb879dbc7df8944669a8aa6e15e158b1484658c4
Parents: 0341826
Author: Andrew Onishuk <aonishuk@hortonworks.com>
Authored: Tue Jul 28 15:52:20 2015 +0300
Committer: Andrew Onishuk <aonishuk@hortonworks.com>
Committed: Tue Jul 28 15:52:20 2015 +0300

----------------------------------------------------------------------
 ambari-agent/src/main/python/ambari_agent/main.py | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/bb879dbc/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 0971cbb..1968996 100644
--- a/ambari-agent/src/main/python/ambari_agent/main.py
+++ b/ambari-agent/src/main/python/ambari_agent/main.py
@@ -47,6 +47,7 @@ from HeartbeatHandlers import bind_signal_handlers
 from ambari_commons.constants import AMBARI_SUDO_BINARY
 logger = logging.getLogger(__name__)
 
+is_logger_setup = False
 formatstr = "%(levelname)s %(asctime)s %(filename)s:%(lineno)d - %(message)s"
 agentPid = os.getpid()
 config = AmbariConfig.AmbariConfig()
@@ -72,6 +73,9 @@ def setup_logging(verbose):
     logging.basicConfig(format=formatstr, level=logging.INFO, filename=AmbariConfig.AmbariConfig.getLogFile())
     logger.setLevel(logging.INFO)
     logger.info("loglevel=logging.INFO")
+    
+  global is_logger_setup
+  is_logger_setup = True
 
 def add_syslog_handler(logger):
     
@@ -239,7 +243,6 @@ def main(heartbeat_stop_callback=None):
   
   default_cfg = {'agent': {'prefix': '/home/ambari'}}
   config.load(default_cfg)
-
   bind_signal_handlers(agentPid)
 
   if (len(sys.argv) > 1) and sys.argv[1] == 'stop':
@@ -303,6 +306,12 @@ def main(heartbeat_stop_callback=None):
   logger.info("finished")
 
 if __name__ == "__main__":
-  heartbeat_stop_callback = bind_signal_handlers(agentPid)
-
-  main(heartbeat_stop_callback)
+  try:
+    heartbeat_stop_callback = bind_signal_handlers(agentPid)
+  
+    main(heartbeat_stop_callback)
+  except:
+    global is_logger_setup
+    if is_logger_setup:
+      logger.exception("Fatal exception occurred:")
+    raise


Mime
View raw message