Repository: ambari
Updated Branches:
  refs/heads/trunk 5a7adeb0e -> 97d9b0595


AMBARI-20504. Ambari-agent log rotation is broken (echekanskiy)


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

Branch: refs/heads/trunk
Commit: 97d9b05956a74a34710a9e2fe77f545e636e7c35
Parents: 5a7adeb
Author: Eugene Chekanskiy <[email protected]>
Authored: Mon Mar 20 20:16:31 2017 +0200
Committer: Eugene Chekanskiy <[email protected]>
Committed: Mon Mar 20 20:16:31 2017 +0200

----------------------------------------------------------------------
 ambari-agent/src/main/python/ambari_agent/main.py | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/97d9b059/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 8e55916..236de25 100644
--- a/ambari-agent/src/main/python/ambari_agent/main.py
+++ b/ambari-agent/src/main/python/ambari_agent/main.py
@@ -107,6 +107,7 @@ import HeartbeatHandlers
 from HeartbeatHandlers import bind_signal_handlers
 from ambari_commons.constants import AMBARI_SUDO_BINARY
 from resource_management.core.logger import Logger
+
 logger = logging.getLogger()
 alerts_logger = logging.getLogger('ambari_alerts')
 
@@ -125,10 +126,17 @@ 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)
 
+_file_logging_handlers ={}
+
 def setup_logging(logger, filename, logging_level):
   formatter = logging.Formatter(formatstr)
-  rotateLog = logging.handlers.RotatingFileHandler(filename, "a", 10000000, 25)
-  rotateLog.setFormatter(formatter)
+
+  if filename in _file_logging_handlers:
+    rotateLog = _file_logging_handlers[filename]
+  else:
+    rotateLog = logging.handlers.RotatingFileHandler(filename, "a", 10000000, 
25)
+    rotateLog.setFormatter(formatter)
+    _file_logging_handlers[filename] = rotateLog
   logger.addHandler(rotateLog)
       
   logging.basicConfig(format=formatstr, level=logging_level, filename=filename)

Reply via email to