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>
# 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.
class TestLogHandler(unittest.TestCase):
- def test(self):
+ def testNormal(self):
tmpfile = tempfile.NamedTemporaryFile()
handler = utils.log._ReopenableLogHandler(tmpfile.name)
# 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))