Changeset 6348 for main


Ignore:
Timestamp:
11 Jun 2011, 10:52:50 (13 years ago)
Author:
Henrik Bettermann
Message:

First test implementation for applicants logger. Uli, please check.

Location:
main/waeup.sirp/trunk/src/waeup/sirp/applicants
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/applicants/applicants.py

    r6347 r6348  
    4747        IWorkflowInfo(self).fireTransition('init')
    4848        return
     49
     50    def getApplicantsRootLogger(self):
     51        return grok.getSite()['applicants'].logger
    4952
    5053    @property
  • main/waeup.sirp/trunk/src/waeup/sirp/applicants/browser.py

    r6336 r6348  
    6161from waeup.sirp.applicants.workflow import create_workflow, INITIALIZED, STARTED
    6262
    63 
    6463results_widget = CustomWidgetFactory(
    6564    WAeUPObjectWidget, ResultEntry)
     
    570569            IWorkflowInfo(self.context).fireTransition(transition_id)
    571570        self.flash('Form has been saved.')
     571        self.context.getApplicantsRootLogger().info('Saved')
    572572        return
    573573
  • main/waeup.sirp/trunk/src/waeup/sirp/applicants/interfaces.py

    r6343 r6348  
    297297    state = Attribute('Returns the application state of an applicant')
    298298
     299    def getApplicantsRootLogger():
     300        """Returns the logger from the applicants root object
     301        """
     302
    299303    reg_no = schema.TextLine(
    300304        title = u'JAMB Registration Number',
  • main/waeup.sirp/trunk/src/waeup/sirp/applicants/root.py

    r6198 r6348  
    2323The root for applicants.
    2424"""
     25import logging
    2526import grok
     27import os
    2628from hurry.query import Eq
    2729from hurry.query.interfaces import IQuery
     
    3638    """
    3739    grok.implements(IApplicantsRoot)
     40
     41    @property
     42    def logger(self):
     43        """Get a logger for applicants.
     44        """
     45        # We need a different logger for every site...
     46        site = grok.getSite()
     47        sitename = getattr(site, '__name__', 'app')
     48        loggername = 'waeup.sirp.%s.applicants' % sitename
     49        logger = logging.getLogger(loggername)
     50        if not logger.handlers:
     51            logger = self._setupLogger(logger)
     52        return logger
     53
     54    def _setupLogger(self, logger):
     55        """Setup applicants logger.
     56        """
     57        logdir = os.path.join(grok.getSite()['datacenter'].storage, 'logs')
     58        if not os.path.exists(logdir):
     59            os.mkdir(logdir)
     60        filename = os.path.join(logdir, 'applicants.log')
     61
     62        # Create a rotating file handler logger for datacenter.
     63        handler = logging.handlers.RotatingFileHandler(
     64            filename, maxBytes=5*1024**1, backupCount=5)
     65        formatter = logging.Formatter(
     66            '%(asctime)s - %(levelname)s - %(message)s')
     67        handler.setFormatter(formatter)
     68
     69        # Here we decide, whether our messages will _also_ go to
     70        # application log.
     71        logger.propagate = False
     72        logger.setLevel(logging.DEBUG)
     73        logger.addHandler(handler)
     74        return logger
    3875
    3976    @property
Note: See TracChangeset for help on using the changeset viewer.