[svn] commit: r1966 - in /branches/trac176/src: bin/xfrout/xfrout.py.in lib/python/isc/log/log.py lib/python/isc/log/tests/log_test.py
BIND 10 source code commits
bind10-changes at lists.isc.org
Fri May 28 15:02:40 UTC 2010
Author: chenzhengzhang
Date: Fri May 28 15:02:40 2010
New Revision: 1966
Log:
Fixed rotate file handler issue.
Modified:
branches/trac176/src/bin/xfrout/xfrout.py.in
branches/trac176/src/lib/python/isc/log/log.py
branches/trac176/src/lib/python/isc/log/tests/log_test.py
Modified: branches/trac176/src/bin/xfrout/xfrout.py.in
==============================================================================
--- branches/trac176/src/bin/xfrout/xfrout.py.in (original)
+++ branches/trac176/src/bin/xfrout/xfrout.py.in Fri May 28 15:02:40 2010
@@ -380,7 +380,7 @@
if self._log:
self._log.update_config(self._config_data.get('log_file'), self._config_data.get('severity'),
- self._config_data.get('max_bytes'), self._config_data.get('versions'))
+ self._config_data.get('versions'), self._config_data.get('max_bytes'))
if self._unix_socket_server:
self._unix_socket_server.update_config_data(self._config_data)
Modified: branches/trac176/src/lib/python/isc/log/log.py
==============================================================================
--- branches/trac176/src/lib/python/isc/log/log.py (original)
+++ branches/trac176/src/lib/python/isc/log/log.py Fri May 28 15:02:40 2010
@@ -50,13 +50,13 @@
if (self.stream) and (not os.path.exists(dfn)): #Is log file exist?
self.stream.close()
self.stream = self._open()
- super(RotatingFileHandler, self).shouldRollover(record)
-
+ return super(RotatingFileHandler, self).shouldRollover(record)
+
def update_config(self, file_name, backup_count, max_bytes):
"""
Update RotatingFileHandler configuration.
- If the file path is not exists, we will use the old configuration.
+ If the file path is not exist, we will use the old log file.
input:
log file name
max backup count
@@ -65,8 +65,8 @@
dir = os.path.split(file_name)
if(os.path.exists(dir[0])):
self.baseFilename = file_name
- self.maxBytes = max_bytes
- self.backupCount = backup_count
+ self.maxBytes = max_bytes
+ self.backupCount = backup_count
class SLHandler(logging.Handler):
"""
@@ -122,8 +122,11 @@
log_to_console = True):
"""
Initializes the logger with some specific parameters
- """
- logging.Logger.__init__(self, log_name)
+
+ If log_to_console is Ture, stream handler will be used;
+ else syslog handler will be used.
+ """
+ super(ModuleLogger, self).__init__(log_name)
# Set up a specific logger with our desired output level
logLevel = LEVELS.get(severity, logging.NOTSET)
@@ -135,7 +138,7 @@
self.syslog_handler = None
self.add_null_handler()
- self.add_rotate_handler(log_file, max_bytes, backup_count)
+ self.add_rotate_handler(log_file, backup_count, max_bytes)
if log_to_console:
self.add_stream_handler()
else:
@@ -148,18 +151,20 @@
self.null_handler = logging.NullHandler()
self.addHandler(self.null_handler)
- def add_rotate_handler(self, log_file, max_bytes, backup_count):
+ def add_rotate_handler(self, log_file, backup_count, max_bytes):
"""
Add a rotate file handler.
input:
- log_file : the location of log file.Handler would't be created is log_file is empty
+ log_file : the location of log file. Handler wouldn't be created
+ if log_file is not specified
max_bytes : limit log growth
backup_count : max backup count
"""
if(log_file != 0 and log_file != ''):
try:
- self.rotating_handler = RotatingFileHandler(filename = log_file, maxBytes = max_bytes,
+ self.rotating_handler = RotatingFileHandler(filename = log_file,
+ maxBytes = max_bytes,
backupCount = backup_count)
except IOError:
self.rotating_handler = None
@@ -186,29 +191,31 @@
"""
self.syslog_handler = SLHandler('BIND10', facility=syslog.LOG_USER)
self.syslog_handler.setFormatter(formatter)
- #set syslog handler level info
+ #set syslog handler severity level INFO
self.syslog_handler.setLevel(logging.INFO)
self.addHandler(self.syslog_handler)
- def update_rotate_handler(self, log_file, max_bytes, backup_count):
- """
- If the rotate handler has been added to the logger, update its configuration,
- else add it to the logger.
-
- If log file is empty, the handler will be removed.
+ def update_rotate_handler(self, log_file, backup_count, max_bytes):
+ """
+ If the rotate file handler has been added to the logger, update its
+ configuration, or add it to the logger.
+
"""
if (self.rotating_handler in self.handlers):
if(log_file != 0 and log_file != ''):
- self.rotating_handler.update_config(log_file, max_bytes, backup_count)
+ self.rotating_handler.update_config(log_file, backup_count, max_bytes)
else:
+ """
+ If log file is empty, the handler will be removed.
+ """
self.rotating_handler.flush()
self.rotating_handler.close()
self.removeHandler(self.rotating_handler)
else:
- self.add_rotate_handler(log_file, max_bytes, backup_count)
-
-
- def update_config(self, file_name, level, max_bytes, backup_count):
+ self.add_rotate_handler(log_file, backup_count, max_bytes)
+
+
+ def update_config(self, file_name, level, backup_count, max_bytes):
"""
Update logger's configuration.
Modified: branches/trac176/src/lib/python/isc/log/tests/log_test.py
==============================================================================
--- branches/trac176/src/lib/python/isc/log/tests/log_test.py (original)
+++ branches/trac176/src/lib/python/isc/log/tests/log_test.py Fri May 28 15:02:40 2010
@@ -5,7 +5,8 @@
class TestRotateFileHandler(unittest.TestCase):
def setUp(self):
- self.handler = RotatingFileHandler('/var/log/rotate_file_handler.log', 1024, 5)
+ self.handler = RotatingFileHandler(filename = '/var/log/rotate_file_handler.log',
+ maxBytes = 1024, backupCount = 5)
def test_shouldRollover(self):
if(os.path.exists('/var/log/rotate_file_handler.log')):
@@ -15,10 +16,15 @@
self.assertTrue(os.path.exists('/var/log/rotate_file_handler.log'))
def test_update_config(self):
- self.handler.update_config('/var/log/rotate_file_handler2.log', 512, 3)
+ self.handler.update_config('/var/log/rotate_file_handler2.log', 3, 512)
self.assertEqual(self.handler.baseFilename, '/var/log/rotate_file_handler2.log')
- self.assertEqual(self.handler.maxBytes, 3)
- self.assertEqual(self.handler.backupCount, 512)
+ self.assertEqual(self.handler.maxBytes, 512)
+ self.assertEqual(self.handler.backupCount, 3)
+
+ self.handler.update_config('/var/ZZZXXX/rotate_file_handler2.log', 4, 1024)
+ self.assertEqual(self.handler.baseFilename, '/var/log/rotate_file_handler2.log')
+ self.assertEqual(self.handler.maxBytes, 1024)
+ self.assertEqual(self.handler.backupCount, 4)
class TestLogging(unittest.TestCase):
@@ -74,11 +80,11 @@
if(self.syslog_logger.rotating_handler in self.syslog_logger.handlers):
self.syslog_logger.removeHandler(self.syslog_logger.rotating_handler)
- self.syslog_logger.add_rotate_handler('', 1024, 5)
+ self.syslog_logger.add_rotate_handler('', 5, 1024)
ret = self.syslog_logger.rotating_handler in self.syslog_logger.handlers
self.assertFalse(ret)
- self.syslog_logger.add_rotate_handler('/var/log/RotateFile.log', 1024, 5)
+ self.syslog_logger.add_rotate_handler('/var/log/RotateFile.log', 5, 1024)
ret = self.syslog_logger.rotating_handler in self.syslog_logger.handlers
self.assertTrue(ret)
@@ -109,7 +115,7 @@
self.file_stream_logger.update_rotate_handler('/var/log/RotateFile', 4, 1024)
ret = self.file_stream_logger.rotating_handler in self.file_stream_logger.handlers
- self.assertFalse(ret)
+ self.assertTrue(ret)
def test_update_config(self):
self.file_stream_logger.update_config('/var/log/RotateFile','error', 4, 1024)
More information about the bind10-changes
mailing list