Ignore:
Timestamp:
27 Jun 2011, 10:20:32 (14 years ago)
Author:
uli
Message:

Remove confusing old implementation of WAeUPLogger.

File:
1 edited

Legend:

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

    r6445 r6480  
    2727import logging
    2828from zope.interface import Interface, Attribute
    29 
    30 marker_ = object()
    31 
    32 class WAeUPLogger(object):
    33 
    34     _logger = None
    35 
    36     def __init__(self, loggername, filename, site=marker_, logdir=marker_,
    37                  handlers=marker_, formatters=marker_, propagate=False,
    38                  level=logging.DEBUG):
    39         self.loggername = loggername
    40         self.filename = filename
    41         self.site = site
    42         self.sitename = None
    43         self.logdir = logdir
    44         self.handlers = handlers
    45         self.formatters = formatters
    46         self.propagate = propagate
    47         self.level = level
    48         self._logger = None
    49         return
    50 
    51 
    52     @property
    53     def logger(self):
    54         if self._logger is not None:
    55             if '__app' in self._logger.name:
    56                 if getattr(self.site, '__name__', None) is not None:
    57                     self.setup()
    58             return self._logger
    59         self.setup()
    60         return self._logger
    61 
    62     def setup(self):
    63         if self.site is marker_:
    64             self.site = grok.getSite()
    65         if '%s' in self.loggername:
    66             name = getattr(self.site, '__name__', '__app')
    67             self.loggername = self.loggername % (name,)
    68         self.logger = logging.getLogger(self.loggername)
    69         self.update()
    70         return
    71 
    72     def update(self):
    73         if self.site is marker_:
    74             self.site = grok.getSite()
    75         if self.logdir is marker_:
    76             self.logdir = os.path.join(self.site['datacenter'].storage, 'logs')
    77         if not os.path.exists(self.logdir):
    78             os.mkdir(self.logdir)
    79         filename = os.path.join(self.logdir, self.filename)
    80 
    81         # Create a rotating file handler logger for datacenter.
    82         if self.handlers is marker_:
    83             self.handlers = [logging.handlers.RotatingFileHandler(
    84                     filename, maxBytes=5*1024**1, backupCount=5)]
    85         if self.formatters is marker_:
    86             self.formatters = [logging.Formatter(
    87                     '%(asctime)s - %(levelname)s - %(message)s')]
    88 
    89         self.logger.propagate = self.propagate
    90         self.logger.setLevel(self.level)
    91 
    92         for handler, formatter in map(lambda x, y: (x,y),
    93                                      self.handlers, self.formatters):
    94             handler.setFormatter(formatter)
    95             self.logger.addHandler(handler)
    96         return self.logger
    97 
    9829
    9930class ISiteLoggers(Interface):
Note: See TracChangeset for help on using the changeset viewer.