diff --git a/Authors b/Authors index e918827c0c..c72bc6dd41 100644 --- a/Authors +++ b/Authors @@ -16,6 +16,7 @@ Josh Kearney Justin Shepherd Ken Pepple Kevin L. Mitchell +Mark McLoughlin Matt Dietz Monty Taylor Rick Clark diff --git a/glance/common/config.py b/glance/common/config.py index f4a734782d..c4f614b2bc 100644 --- a/glance/common/config.py +++ b/glance/common/config.py @@ -173,7 +173,7 @@ def setup_logging(options, conf): logdir = conf.get('log_dir') if logdir: logfile = os.path.join(logdir, logfile) - handler = logging.FileHandler(logfile) + handler = logging.handlers.WatchedFileHandler(logfile) else: handler = logging.StreamHandler(sys.stdout) diff --git a/glance/tests/functional/test_logging.py b/glance/tests/functional/test_logging.py index 8198fa926c..7f0e6e7aff 100644 --- a/glance/tests/functional/test_logging.py +++ b/glance/tests/functional/test_logging.py @@ -17,7 +17,9 @@ """Functional test case that tests logging output""" +import httplib2 import os +import stat import unittest from glance.tests import functional @@ -75,3 +77,26 @@ class TestLogging(functional.FunctionalTest): self.assertFalse('DEBUG [glance-registry]' in registry_log_out) self.stop_servers() + + def assertNotEmptyFile(self, path): + self.assertTrue(os.path.exists(path)) + self.assertNotEqual(os.stat(path)[stat.ST_SIZE], 0) + + def test_logrotate(self): + """ + Test that we notice when our log file has been rotated + """ + self.cleanup() + self.start_servers() + + self.assertNotEmptyFile(self.api_server.log_file) + + os.rename(self.api_server.log_file, self.api_server.log_file + ".1") + + path = "http://%s:%d/" % ("0.0.0.0", self.api_port) + response, content = httplib2.Http().request(path, 'GET') + self.assertEqual(response.status, 300) + + self.assertNotEmptyFile(self.api_server.log_file) + + self.stop_servers()