Changeset 6754 for main/waeup.sirp/trunk


Ignore:
Timestamp:
14 Sep 2011, 00:48:11 (13 years ago)
Author:
uli
Message:

Logger-related stuff.

Location:
main/waeup.sirp/trunk/src/waeup/sirp
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/browser/batchprocessing.txt

    r6734 r6754  
    557557    >>> 'datacenter.log' in browser.contents
    558558    True
    559     >>> browser.getControl('Show', index=1).click()
     559    >>> browser.getControl('Show', index=0).click()
    560560    >>> '<input type="submit" name="back" value="Back" />' in browser.contents
    561561    True
  • main/waeup.sirp/trunk/src/waeup/sirp/interfaces.py

    r6569 r6754  
    484484        paths.
    485485        """
     486
     487class ILoggerCollector(Interface):
     488
     489    def getLoggers(site):
     490        """Return all loggers registered for `site`.
     491        """
     492
     493    def registerLogger(site, logging_component):
     494        """Register a logging component residing in `site`.
     495        """
     496
     497    def unregisterLogger(site, logging_component):
     498        """Unregister a logger.
     499        """
  • main/waeup.sirp/trunk/src/waeup/sirp/testing.py

    r6747 r6754  
    284284    doctest.REPORT_NDIFF + doctest.ELLIPSIS + doctest.NORMALIZE_WHITESPACE)
    285285
     286def clear_logger_collector():
     287    from zope.component import queryUtility, getGlobalSiteManager
     288    from waeup.sirp.interfaces import ILoggerCollector
     289    collector = queryUtility(ILoggerCollector)
     290    if collector is None:
     291        return
     292    keys = collector.keys()
     293    for key in keys:
     294        del collector[key]
     295    return
     296
    286297class FunctionalTestCase(FunctionalTestCase):
    287298    """A test case that supports checking output diffs in doctest style.
     
    296307        super(FunctionalTestCase, self).tearDown()
    297308        remove_new_loggers(self.functional_old_loggers)
     309        clear_logger_collector()
    298310        return
    299311
  • main/waeup.sirp/trunk/src/waeup/sirp/utils/logger.py

    r6745 r6754  
    8484from zope.component import queryUtility
    8585from zope.interface import Interface, Attribute, implements
    86 from waeup.sirp.interfaces import IDataCenter, IDataCenterStorageMovedEvent
     86from waeup.sirp.interfaces import (
     87    IDataCenter, IDataCenterStorageMovedEvent, ILoggerCollector)
    8788
    8889#: Default logfile size (5 KB)
     
    300301
    301302
    302 class ILoggerCollector(Interface):
    303 
    304     def getLoggers(site):
    305         """Return all loggers registered for `site`.
    306         """
    307 
    308     def registerLogger(site, logging_component):
    309         """Register a logging component residing in `site`.
    310         """
    311 
    312     def unregisterLogger(site, logging_component):
    313         """Unregister a logger.
    314         """
    315 
    316303class LoggerCollector(dict, grok.GlobalUtility):
    317304    """A global utility providing `ILoggerCollector`.
     
    380367            logger.logger_logfile_changed()
    381368    return
     369
     370from waeup.sirp.interfaces import IUniversity
     371@grok.subscribe(IUniversity, grok.IObjectRemovedEvent)
     372def handle_site_removal(obj, event):
     373    collector = queryUtility(ILoggerCollector)
     374    name = getattr(obj, '__name__', None)
     375    if name is None:
     376        return
     377    if name not in collector.keys():
     378        return
     379    del collector[name]
     380    return
  • main/waeup.sirp/trunk/src/waeup/sirp/utils/tests/test_logger.py

    r6748 r6754  
    88from zope.interface.verify import verifyClass, verifyObject
    99from waeup.sirp.app import University
    10 from waeup.sirp.testing import (
    11     FunctionalLayer, FunctionalTestCase, get_all_loggers,
    12     remove_new_loggers, remove_logger)
     10from waeup.sirp.testing import FunctionalLayer, FunctionalTestCase
    1311
    1412from waeup.sirp.utils.logger import (
     
    259257    def setUp(self):
    260258        super(LoggerCollectorTests, self).setUp()
    261         self.old_loggers = get_all_loggers()
    262259        # Setup a sample site for each test
    263260        app = University()
     
    281278    def tearDown(self):
    282279        super(LoggerCollectorTests, self).tearDown()
    283         remove_new_loggers(self.old_loggers)
    284280        shutil.rmtree(self.workdir)
    285281        shutil.rmtree(self.dc_root)
     
    357353    def setUp(self):
    358354        super(LogfileChangeTests, self).setUp()
    359         remove_logger('waeup.sirp.app') # In case it lingers around
    360         self.old_loggers = get_all_loggers()
    361355        # Setup a sample site for each test
    362356        app = University()
     
    373367        self.component = self.app['mycomponent']
    374368        setSite(self.app)
    375 
    376369        self.component = LoggingComponent()
    377370        return
     
    379372    def tearDown(self):
    380373        super(LogfileChangeTests, self).tearDown()
    381         remove_new_loggers(self.old_loggers)
    382374        shutil.rmtree(self.workdir)
    383375        shutil.rmtree(self.dc_root)
     
    397389        self.assertTrue(filename2.startswith(self.dc_root_new))
    398390        return
     391
     392    def test_storage_deletion(self):
     393        # When a site is deleted, the loggers should go away as well
     394        self.dc_root_new = tempfile.mkdtemp()
     395        logger1 = self.component.logger.handlers # create entry in collector
     396        collector = queryUtility(ILoggerCollector)
     397        loggers1 = collector.keys()
     398        root = self.app.__parent__
     399        del root['app']
     400        loggers2 = collector.keys()
     401        self.assertEqual(loggers1, ['app'])
     402        self.assertEqual(loggers2, [])
     403        return
Note: See TracChangeset for help on using the changeset viewer.