ia64/xen-unstable

changeset 9228:83a882b3d807

Untangle XendRoot and XendLogging by having XendLogging check the global
params.XEND_DEBUG value itself. This removes the need for addLogStderr and
removeLogStderr. Remove the maxBytes and backupCount parameters to init, as
they are unused and we only use the hardcoded values anyway.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@leeni.uk.xensource.com
date Fri Mar 10 11:38:15 2006 +0100 (2006-03-10)
parents cc303cdf8809
children faa1eb1621b9
files tools/python/xen/xend/XendLogging.py tools/python/xen/xend/XendRoot.py
line diff
     1.1 --- a/tools/python/xen/xend/XendLogging.py	Fri Mar 10 11:05:59 2006 +0100
     1.2 +++ b/tools/python/xen/xend/XendLogging.py	Fri Mar 10 11:38:15 2006 +0100
     1.3 @@ -13,7 +13,7 @@
     1.4  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     1.5  #============================================================================
     1.6  # Copyright (C) 2004, 2005 Mike Wray <mike.wray@hp.com>
     1.7 -# Copyright (C) 2005 XenSource Ltd
     1.8 +# Copyright (C) 2005, 2006 XenSource Ltd.
     1.9  #============================================================================
    1.10  
    1.11  
    1.12 @@ -22,9 +22,10 @@ import types
    1.13  import logging
    1.14  import logging.handlers
    1.15  
    1.16 +from xen.xend.server import params
    1.17  
    1.18 -__all__ = [ 'log', 'init', 'getLogFilename', 'addLogStderr',
    1.19 -            'removeLogStderr' ]
    1.20 +
    1.21 +__all__ = [ 'log', 'init', 'getLogFilename' ]
    1.22  
    1.23  
    1.24  if not 'TRACE' in logging.__dict__:
    1.25 @@ -38,37 +39,28 @@ if not 'TRACE' in logging.__dict__:
    1.26  log = logging.getLogger("xend")
    1.27  
    1.28  
    1.29 -DEFAULT_MAX_BYTES = 1 << 20  # 1MB
    1.30 -DEFAULT_BACKUP_COUNT = 5
    1.31 +MAX_BYTES = 1 << 20  # 1MB
    1.32 +BACKUP_COUNT = 5
    1.33  
    1.34  STDERR_FORMAT = "[%(name)s] %(levelname)s (%(module)s:%(lineno)d) %(message)s"
    1.35  LOGFILE_FORMAT = "[%(asctime)s %(name)s] %(levelname)s (%(module)s:%(lineno)d) %(message)s"
    1.36  DATE_FORMAT = "%Y-%m-%d %H:%M:%S"
    1.37  
    1.38  
    1.39 -stderrHandler = logging.StreamHandler()
    1.40 -stderrHandler.setFormatter(logging.Formatter(STDERR_FORMAT, DATE_FORMAT))
    1.41 -
    1.42  logfilename = None
    1.43  
    1.44  
    1.45 -def init(filename, level=logging.INFO, maxBytes=None, backupCount=None):
    1.46 -    """Initialise logging. Logs to 'filename' by default, but does not log to
    1.47 -    stderr unless addLogStderr() is called.
    1.48 +def init(filename, level):
    1.49 +    """Initialise logging.  Logs to the given filename, and logs to stderr if
    1.50 +    XEND_DEBUG is set.
    1.51      """
    1.52  
    1.53      global logfilename
    1.54  
    1.55      def openFileHandler(fname):
    1.56 -        return logging.handlers.RotatingFileHandler(fname,
    1.57 -                                                    mode='a',
    1.58 -                                                    maxBytes=maxBytes,
    1.59 -                                                    backupCount=backupCount)
    1.60 -
    1.61 -    if not maxBytes:
    1.62 -        maxBytes = DEFAULT_MAX_BYTES
    1.63 -    if not backupCount:
    1.64 -        backupCount = DEFAULT_BACKUP_COUNT
    1.65 +        return logging.handlers.RotatingFileHandler(fname, mode = 'a',
    1.66 +                                                    maxBytes = MAX_BYTES,
    1.67 +                                                    backupCount = BACKUP_COUNT)
    1.68  
    1.69      # Rather unintuitively, getLevelName will get the number corresponding to
    1.70      # a level name, as well as getting the name corresponding to a level
    1.71 @@ -89,16 +81,12 @@ def init(filename, level=logging.INFO, m
    1.72      fileHandler.setFormatter(logging.Formatter(LOGFILE_FORMAT, DATE_FORMAT))
    1.73      log.addHandler(fileHandler)
    1.74  
    1.75 +    if params.XEND_DEBUG:
    1.76 +        stderrHandler = logging.StreamHandler()
    1.77 +        stderrHandler.setFormatter(logging.Formatter(STDERR_FORMAT,
    1.78 +                                                     DATE_FORMAT))
    1.79 +        log.addHandler(stderrHandler)
    1.80 +
    1.81  
    1.82  def getLogFilename():
    1.83      return logfilename
    1.84 -
    1.85 -
    1.86 -def addLogStderr():
    1.87 -    """Add logging to stderr."""
    1.88 -    log.addHandler(stderrHandler)
    1.89 -
    1.90 -
    1.91 -def removeLogStderr():
    1.92 -    """Remove logging to stderr."""
    1.93 -    log.removeHandler(stderrHandler)
     2.1 --- a/tools/python/xen/xend/XendRoot.py	Fri Mar 10 11:05:59 2006 +0100
     2.2 +++ b/tools/python/xen/xend/XendRoot.py	Fri Mar 10 11:38:15 2006 +0100
     2.3 @@ -102,15 +102,14 @@ class XendRoot:
     2.4          """
     2.5          print >>sys.stderr, "xend [ERROR]", fmt % args
     2.6  
     2.7 +
     2.8      def configure(self):
     2.9          self.set_config()
    2.10 -        logfile = self.get_config_value("logfile", self.logfile_default)
    2.11 -        loglevel = self.get_config_value("loglevel", self.loglevel_default)
    2.12 -        XendLogging.init(logfile, level = loglevel)
    2.13 +        XendLogging.init(self.get_config_value("logfile",
    2.14 +                                               self.logfile_default),
    2.15 +                         self.get_config_value("loglevel",
    2.16 +                                               self.loglevel_default))
    2.17  
    2.18 -        from xen.xend.server import params
    2.19 -        if params.XEND_DEBUG:
    2.20 -            XendLogging.addLogStderr()
    2.21  
    2.22      def set_config(self):
    2.23          """If the config file exists, read it. If not, ignore it.