Reopen log file only once after SIGHUP
authorMichael Hanselmann <hansmi@google.com>
Mon, 25 Jul 2011 11:08:22 +0000 (13:08 +0200)
committerMichael Hanselmann <hansmi@google.com>
Mon, 25 Jul 2011 13:01:44 +0000 (15:01 +0200)
Commit b6fa9a44 added a re-openable log handler. The log file is
reopened when a daemon is sent a HUP signal. Due to a bug in the code,
fixed by this patch, the log file would be reopened for every single log
message thereafter.

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>

lib/utils/log.py
test/ganeti.utils.log_unittest.py

index 5100800..d5d3c3d 100644 (file)
@@ -70,6 +70,9 @@ class _ReopenableLogHandler(logging.handlers.BaseRotatingHandler):
     # TODO: Handle errors?
     self.stream = open(self.baseFilename, "a")
 
+    # Don't reopen on the next message
+    self._reopen = False
+
   def RequestReopen(self):
     """Register a request to reopen the file.
 
index 8594fb8..5ae860b 100755 (executable)
@@ -35,7 +35,7 @@ import testutils
 
 
 class TestLogHandler(unittest.TestCase):
-  def test(self):
+  def testNormal(self):
     tmpfile = tempfile.NamedTemporaryFile()
 
     handler = utils.log._ReopenableLogHandler(tmpfile.name)
@@ -84,6 +84,10 @@ class TestLogHandler(unittest.TestCase):
     # Write another message, should reopen
     for _ in range(4):
       logger.info("Test message INFO")
+
+      # Flag must be reset
+      self.assertFalse(handler._reopen)
+
       self.assertFalse(utils.VerifyFileID(utils.GetFileID(tmpfile.name),
                                           before_id))