Ignore:
Timestamp:
24 Feb 2013, 13:42:04 (12 years ago)
Author:
uli
Message:

Use WatchedFileHandler? instead of DatedRotatingFileHandler? for logging.

Location:
main/waeup.kofa/trunk/src/waeup/kofa/utils
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/utils/logger.py

    r9769 r9988  
    7676import grok
    7777import logging
     78from logging.handlers import WatchedFileHandler
    7879from string import Template
    7980from ulif.loghandlers import DatedRotatingFileHandler
     
    215216
    216217        # Create a rotating file handler logger.
    217         handler = DatedRotatingFileHandler(
    218             filename, when='MON', backupCount=BACKUP_COUNT)
     218        handler = WatchedFileHandler(
     219            filename, encoding='utf-8')
     220        #handler = DatedRotatingFileHandler(
     221        #    filename, when='MON', backupCount=BACKUP_COUNT)
    219222        handler.setLevel(LEVEL)
    220223        formatter = logging.Formatter(self.logger_format_str)
  • main/waeup.kofa/trunk/src/waeup/kofa/utils/tests/test_logger.py

    r9283 r9988  
    162162        self.assertEqual(len(result.handlers), 1)
    163163        handler = result.handlers[0]
    164         #self.assertEqual(handler.maxBytes, MAX_BYTES)
    165         self.assertEqual(handler.backupCount, BACKUP_COUNT)
     164        if hasattr(handler, 'maxBytes'):
     165            self.assertEqual(handler.maxBytes, MAX_BYTES)
     166        if hasattr(handler, 'backupCount'):
     167            self.assertEqual(handler.backupCount, BACKUP_COUNT)
    166168        self.assertTrue(result.propagate is False)
    167169        return
     
    209211        self.assertEqual(new_handler_num, 1)
    210212        self.assertTrue(isinstance(
    211                 new_py_logger.handlers[0],
    212                 logging.handlers.RotatingFileHandler))
     213            new_py_logger.handlers[0],
     214            logging.handlers.WatchedFileHandler))
    213215
    214216class LoggersFunctionalTests(FunctionalTestCase):
     
    254256        handler = self.component.logger.handlers[0]
    255257        self.assertTrue(isinstance(
    256                 handler, logging.handlers.RotatingFileHandler))
    257         #self.assertEqual(handler.maxBytes, MAX_BYTES)
    258         self.assertEqual(handler.backupCount, BACKUP_COUNT)
     258                handler, logging.handlers.WatchedFileHandler))
     259        if hasattr(handler, 'maxBytes'):
     260            self.assertEqual(handler.maxBytes, MAX_BYTES)
     261        if hasattr(handler, 'backupCount'):
     262            self.assertEqual(handler.backupCount, BACKUP_COUNT)
    259263        self.assertTrue(handler.baseFilename.endswith('logs/sample.log'))
    260264        return
Note: See TracChangeset for help on using the changeset viewer.