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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.