Changeset 6445


Ignore:
Timestamp:
21 Jun 2011, 01:00:45 (14 years ago)
Author:
uli
Message:
  • Reorder imports
  • Remove outdated stuff
  • Fixes.
File:
1 edited

Legend:

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

    r6440 r6445  
    2626import grok
    2727import logging
     28from zope.interface import Interface, Attribute
    2829
    2930marker_ = object()
    30 
    31 def setup_logger(loggername, filename, site=marker_, logdir=marker_,
    32                  handler=marker_, formatter=marker_, propagate=False,
    33                  level=logging.DEBUG):
    34     """Create a logger.
    35     """
    36     if site is marker_:
    37         site = grok.getSite()
    38     if '%s' in loggername:
    39         name = getattr(site, '__name__', 'app')
    40         loggername = loggername % (name,)
    41     logger = logging.getLogger(loggername)
    42     update_logger(logger, filename, site=site, logdir=logdir, handler=handler,
    43                   formatter=formatter, propagate=propagate, level=level)
    44     return logger, loggername
    45 
    46 def update_logger(logger, filename, site=marker_, logdir=marker_,
    47                   handler=marker_, formatter=marker_, propagate=False,
    48                   level=logging.DEBUG):
    49     if site is marker_:
    50         site = grok.getSite()
    51     if logdir is marker_:
    52         logdir = os.path.join(site['datacenter'].storage, 'logs')
    53     if not os.path.exists(logdir):
    54         os.mkdir(logdir)
    55     filename = os.path.join(logdir, filename)
    56 
    57     # Create a rotating file handler logger for datacenter.
    58     if handler is marker_:
    59         handler = logging.handlers.RotatingFileHandler(
    60             filename, maxBytes=5*1024**1, backupCount=5)
    61     if formatter is marker_:
    62         formatter = logging.Formatter(
    63             '%(asctime)s - %(levelname)s - %(message)s')
    64     handler.setFormatter(formatter)
    65 
    66     logger.propagate = propagate
    67     logger.setLevel(level)
    68     logger.addHandler(handler)
    69     return logger
    70 
    71 def get_logger(loggername, filename, site=marker_, **kw):
    72     """Get a logger.
    73     """
    74     if '%s' in loggername:
    75         if site is marker_:
    76             site = grok.getSite()
    77         loggername = loggername % (
    78             getattr(site, '__name__', 'app'))
    79     logger = logging.getLogger(loggername)
    80     if not logger.handlers:
    81         kw.update(dict(site=site))
    82         logger, loggername = setup_logger(
    83             loggername, filename, **kw)
    84     return logger
    8531
    8632class WAeUPLogger(object):
     
    11763        if self.site is marker_:
    11864            self.site = grok.getSite()
    119         if '%s' in loggername:
    120             name = getattr(site, '__name__', '__app')
    121             loggername = loggername % (name,)
    122         self.logger = logging.getLogger(loggername)
     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)
    12369        self.update()
    12470        return
     
    12874            self.site = grok.getSite()
    12975        if self.logdir is marker_:
    130             self.logdir = os.path.join(site['datacenter'].storage, 'logs')
     76            self.logdir = os.path.join(self.site['datacenter'].storage, 'logs')
    13177        if not os.path.exists(self.logdir):
    13278            os.mkdir(self.logdir)
     
    13783            self.handlers = [logging.handlers.RotatingFileHandler(
    13884                    filename, maxBytes=5*1024**1, backupCount=5)]
    139         if formatters is marker_:
    140             formatters = [logging.Formatter(
     85        if self.formatters is marker_:
     86            self.formatters = [logging.Formatter(
    14187                    '%(asctime)s - %(levelname)s - %(message)s')]
    14288
     
    15096        return self.logger
    15197
    152 
    153 from zope import schema
    154 from zope.interface import Interface, Attribute
    15598
    15699class ISiteLoggers(Interface):
Note: See TracChangeset for help on using the changeset viewer.