Ignore:
Timestamp:
21 Jun 2011, 00:52:54 (13 years ago)
Author:
uli
Message:

With help of the new logger components we can make applicants root
much shorter.

File:
1 edited

Legend:

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

    r6392 r6444  
    2323The root for applicants.
    2424"""
    25 import logging
    2625import grok
    27 import os
    2826from hurry.query import Eq
    2927from hurry.query.interfaces import IQuery
    3028from zope.component import getUtility
    3129from waeup.sirp.interfaces import IWAeUPSIRPPluggable
     30from waeup.sirp.utils.logger import ISiteLoggers
    3231from waeup.sirp.applicants.interfaces import IApplicantsRoot
    3332
     
    4443        """Get a logger for applicants.
    4544        """
    46         # We need a different logger for every site...
    47         site = grok.getSite()
    48         sitename = getattr(site, '__name__', 'app')
    49         loggername = 'waeup.sirp.%s.applicants' % sitename
    50         logger = logging.getLogger(loggername)
    51         if not logger.handlers:
    52             logger = self._setupLogger(logger)
    53         return logger
    54 
    55     def _setupLogger(self, logger):
    56         """Setup applicants logger.
    57         """
    58         logdir = os.path.join(grok.getSite()['datacenter'].storage, 'logs')
    59         if not os.path.exists(logdir):
    60             os.mkdir(logdir)
    61         filename = os.path.join(logdir, 'applicants.log')
    62 
    63         # Create a rotating file handler logger for datacenter.
    64         handler = logging.handlers.RotatingFileHandler(
    65             filename, maxBytes=5*1024**1, backupCount=5)
    66         formatter = logging.Formatter(
    67             '%(asctime)s - %(levelname)s - %(message)s')
    68         handler.setFormatter(formatter)
    69 
    70         # Here we decide, whether our messages will _also_ go to
    71         # application log.
    72         logger.propagate = False
    73         logger.setLevel(logging.DEBUG)
    74         logger.addHandler(handler)
    75         return logger
    76 
     45        loggers = getUtility(ISiteLoggers).getLoggers()
     46        if 'waeup.sirp.%s.applicants' not in loggers.keys():
     47            loggers.register('waeup.sirp.%s.applicants')
     48        return loggers.getLogger('waeup.sirp.%s.applicants')
    7749
    7850class ApplicantsPlugin(grok.GlobalUtility):
Note: See TracChangeset for help on using the changeset viewer.