Changeset 4873 for waeup


Ignore:
Timestamp:
22 Jan 2010, 12:49:37 (15 years ago)
Author:
uli
Message:

Create a datacenter logger.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • waeup/trunk/src/waeup/datacenter.py

    r4858 r4873  
    44tools for importing/exporting CSV data.
    55"""
     6import logging
    67import os
    78import struct
     
    1920    grok.implements(IDataCenter)
    2021    storage = os.path.join(os.path.dirname(__file__), 'files')
     22
     23    @property
     24    def logger(self):
     25        """Get a logger for datacenter actions.
     26        """
     27        # We need a different logger for every site...
     28        site = grok.getSite()
     29        sitename = site.__name__
     30        loggername = 'waeup.sirp.%s.datacenter' % sitename
     31        logger = logging.getLogger(loggername)
     32        if not logger.handlers:
     33            logger = self._setupLogger(logger)
     34        return logger
     35
     36    def _setupLogger(self, logger):
     37        """Setup datacenter logger.
     38        """
     39        logdir = os.path.join(self.storage, 'logs')
     40        if not os.path.exists(logdir):
     41            os.mkdir(logdir)
     42        filename = os.path.join(logdir, 'datacenter.log')
     43
     44        # Create a rotating file handler logger for datacenter.
     45        handler = logging.handlers.RotatingFileHandler(
     46            filename, maxBytes=5*1024**1, backupCount=5)
     47        formatter = logging.Formatter(
     48            '%(asctime)s - %(levelname)s - %(message)s')
     49        handler.setFormatter(formatter)
     50       
     51        # Here we decide, whether our messages will _also_ go to
     52        # application log.
     53        logger.propagate = False
     54        logger.addHandler(handler)
     55        return logger
    2156
    2257    def getReceivers(self):
     
    105140            not_copied = copyFileSystemTree(self.storage, path,
    106141                                            overwrite=overwrite)
    107        
    108142        self.storage = path
    109143        return not_copied
Note: See TracChangeset for help on using the changeset viewer.