def reset_after_updates(self):
     """
     Configure the pyutilib.component logging facility.  This will
     implicitly configure all of the environment-specific logging
     objects.
     """
     sys.stdout.flush()
     logger = logging.getLogger('pyutilib.component.core.' + self.namespace)
     if not self._hdlr is None:
         logger.removeHandler(self._hdlr)
     #
     # Set logging level
     #
     level = self.log_level
     level = level.upper()
     if level in ('DEBUG', 'ALL'):
         logger.setLevel(logging.DEBUG)
     elif level == 'INFO':
         logger.setLevel(logging.INFO)
     elif level == 'ERROR':
         logger.setLevel(logging.ERROR)
     elif level == 'CRITICAL':
         logger.setLevel(logging.CRITICAL)
     else:
         logger.setLevel(logging.WARNING)
     #
     # Initialize the current path.  Is there a rule to use for whic
     # environment will be used???  In practice, there is likely to be
     # only one environment.
     #
     if self.log_dir is None:
         path = None
         for plugin in self.env_plugins:
             (flag, count) = plugin.matches(self.namespace)
             tmp = plugin.get_option("path")
             if flag and not tmp is None:
                 path = tmp
                 break
         if path is None:
             path = os.getcwd()
     else:
         path = self.log_dir
     #
     # Setup the logging file
     #
     logtype = self.log_type.lower()
     if self.log_file is None:
         logfile = os.path.join(path, 'log')
     else:
         logfile = self.log_file
         if not os.path.isabs(logfile):
             logfile = os.path.join(path, logfile)
     #
     # Define the format
     #
     format = self.log_format
     if format is None:
         format = '[env=%(env)s where=%(module)s] %(levelname)s - %(message)s'
         if self.timestamp and logtype in ('file', 'stderr'):
             format = '%(asctime)s ' + format
         format = format.replace('$(', '%(') \
                 .replace('%(env)s', PluginGlobals.get_env().name)
     datefmt = ''
     if self.timestamp and self.log_type == 'stderr':
         datefmt = '%X'
     formatter = logging.Formatter(format, datefmt)
     #
     #  Define the handler
     #
     if logtype == 'file':
         hdlr = logging.FileHandler(logfile)
     elif logtype in ('winlog', 'eventlog', 'nteventlog'):
         # Requires win32 extensions
         hdlr = handlers.NTEventLogHandler(logid, logtype='Application')
     elif logtype in ('syslog', 'unix'):
         hdlr = handlers.SysLogHandler('/dev/log')
     elif logtype in ('stderr'):
         hdlr = logging.StreamHandler(sys.stderr)
     else:
         hdlr = handlers.BufferingHandler(0)
         # Note: this _really_ throws away log events, as a `MemoryHandler`
         # would keep _all_ records in case there's no target handler (a bug?)
     self._hdlr = hdlr
     self._logtype = logtype
     self._logfile = logfile
     hdlr.setFormatter(formatter)
     logger.addHandler(hdlr)
     self._log = logger
Example #2
0
 def reset_after_updates(self):
     """
     Configure the pyutilib.component logging facility.  This will
     implicitly configure all of the environment-specific logging
     objects.
     """
     sys.stdout.flush()
     logger = logging.getLogger('pyutilib.component.core.' + self.namespace)
     if not self._hdlr is None:
         logger.removeHandler(self._hdlr)
     #
     # Set logging level
     #
     level = self.log_level
     level = level.upper()
     if level in ('DEBUG', 'ALL'):
         logger.setLevel(logging.DEBUG)
     elif level == 'INFO':
         logger.setLevel(logging.INFO)
     elif level == 'ERROR':
         logger.setLevel(logging.ERROR)
     elif level == 'CRITICAL':
         logger.setLevel(logging.CRITICAL)
     else:
         logger.setLevel(logging.WARNING)
     #
     # Initialize the current path.  Is there a rule to use for whic
     # environment will be used???  In practice, there is likely to be
     # only one environment.
     #
     if self.log_dir is None:
         path = None
         for plugin in self.env_plugins:
             (flag, count) = plugin.matches(self.namespace)
             tmp = plugin.get_option("path")
             if flag and not tmp is None:
                 path = tmp
                 break
         if path is None:
             path = os.getcwd()
     else:
         path = self.log_dir
     #
     # Setup the logging file
     #
     logtype = self.log_type.lower()
     if self.log_file is None:
         logfile = os.path.join(path, 'log')
     else:
         logfile = self.log_file
         if not os.path.isabs(logfile):
             logfile = os.path.join(path, logfile)
     #
     # Define the format
     #
     format = self.log_format
     if format is None:
         format = '[env=%(env)s where=%(module)s] %(levelname)s - %(message)s'
         if self.timestamp and logtype in ('file', 'stderr'):
             format = '%(asctime)s ' + format
         format = format.replace('$(', '%(') \
                 .replace('%(env)s', PluginGlobals.get_env().name)
     datefmt = ''
     if self.timestamp and self.log_type == 'stderr':
         datefmt = '%X'
     formatter = logging.Formatter(format, datefmt)
     #
     #  Define the handler
     #
     if logtype == 'file':
         hdlr = logging.FileHandler(logfile)
     elif logtype in ('winlog', 'eventlog', 'nteventlog'):
         # Requires win32 extensions
         hdlr = handlers.NTEventLogHandler(logid, logtype='Application')
     elif logtype in ('syslog', 'unix'):
         hdlr = handlers.SysLogHandler('/dev/log')
     elif logtype in ('stderr'):
         hdlr = logging.StreamHandler(sys.stderr)
     else:
         hdlr = handlers.BufferingHandler(0)
         # Note: this _really_ throws away log events, as a `MemoryHandler`
         # would keep _all_ records in case there's no target handler (a bug?)
     self._hdlr = hdlr
     self._logtype = logtype
     self._logfile = logfile
     hdlr.setFormatter(formatter)
     logger.addHandler(hdlr)
     self._log = logger