Changeset 6480 for main/waeup.sirp/trunk/src/waeup/sirp
- Timestamp:
- 27 Jun 2011, 10:20:32 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/utils/logger.py
r6445 r6480 27 27 import logging 28 28 from zope.interface import Interface, Attribute 29 30 marker_ = object()31 32 class WAeUPLogger(object):33 34 _logger = None35 36 def __init__(self, loggername, filename, site=marker_, logdir=marker_,37 handlers=marker_, formatters=marker_, propagate=False,38 level=logging.DEBUG):39 self.loggername = loggername40 self.filename = filename41 self.site = site42 self.sitename = None43 self.logdir = logdir44 self.handlers = handlers45 self.formatters = formatters46 self.propagate = propagate47 self.level = level48 self._logger = None49 return50 51 52 @property53 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._logger59 self.setup()60 return self._logger61 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 return71 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.propagate90 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.logger97 98 29 99 30 class ISiteLoggers(Interface):
Note: See TracChangeset for help on using the changeset viewer.