# HG changeset patch
# User emellor@xxxxxxxxxxxxxxxxxxxxxx
# Node ID 83a882b3d8072616f4169d6b0c858e29bb27ed87
# Parent cc303cdf88099ecdae5b1be53b3ef1cadee2df28
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@xxxxxxxxxxxxx>
diff -r cc303cdf8809 -r 83a882b3d807 tools/python/xen/xend/XendLogging.py
--- a/tools/python/xen/xend/XendLogging.py Fri Mar 10 10:05:59 2006
+++ b/tools/python/xen/xend/XendLogging.py Fri Mar 10 10:38:15 2006
@@ -13,7 +13,7 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#============================================================================
# Copyright (C) 2004, 2005 Mike Wray <mike.wray@xxxxxx>
-# Copyright (C) 2005 XenSource Ltd
+# Copyright (C) 2005, 2006 XenSource Ltd.
#============================================================================
@@ -22,9 +22,10 @@
import logging
import logging.handlers
+from xen.xend.server import params
-__all__ = [ 'log', 'init', 'getLogFilename', 'addLogStderr',
- 'removeLogStderr' ]
+
+__all__ = [ 'log', 'init', 'getLogFilename' ]
if not 'TRACE' in logging.__dict__:
@@ -38,37 +39,28 @@
log = logging.getLogger("xend")
-DEFAULT_MAX_BYTES = 1 << 20 # 1MB
-DEFAULT_BACKUP_COUNT = 5
+MAX_BYTES = 1 << 20 # 1MB
+BACKUP_COUNT = 5
STDERR_FORMAT = "[%(name)s] %(levelname)s (%(module)s:%(lineno)d) %(message)s"
LOGFILE_FORMAT = "[%(asctime)s %(name)s] %(levelname)s (%(module)s:%(lineno)d)
%(message)s"
DATE_FORMAT = "%Y-%m-%d %H:%M:%S"
-stderrHandler = logging.StreamHandler()
-stderrHandler.setFormatter(logging.Formatter(STDERR_FORMAT, DATE_FORMAT))
-
logfilename = None
-def init(filename, level=logging.INFO, maxBytes=None, backupCount=None):
- """Initialise logging. Logs to 'filename' by default, but does not log to
- stderr unless addLogStderr() is called.
+def init(filename, level):
+ """Initialise logging. Logs to the given filename, and logs to stderr if
+ XEND_DEBUG is set.
"""
global logfilename
def openFileHandler(fname):
- return logging.handlers.RotatingFileHandler(fname,
- mode='a',
- maxBytes=maxBytes,
- backupCount=backupCount)
-
- if not maxBytes:
- maxBytes = DEFAULT_MAX_BYTES
- if not backupCount:
- backupCount = DEFAULT_BACKUP_COUNT
+ return logging.handlers.RotatingFileHandler(fname, mode = 'a',
+ maxBytes = MAX_BYTES,
+ backupCount = BACKUP_COUNT)
# Rather unintuitively, getLevelName will get the number corresponding to
# a level name, as well as getting the name corresponding to a level
@@ -89,16 +81,12 @@
fileHandler.setFormatter(logging.Formatter(LOGFILE_FORMAT, DATE_FORMAT))
log.addHandler(fileHandler)
+ if params.XEND_DEBUG:
+ stderrHandler = logging.StreamHandler()
+ stderrHandler.setFormatter(logging.Formatter(STDERR_FORMAT,
+ DATE_FORMAT))
+ log.addHandler(stderrHandler)
+
def getLogFilename():
return logfilename
-
-
-def addLogStderr():
- """Add logging to stderr."""
- log.addHandler(stderrHandler)
-
-
-def removeLogStderr():
- """Remove logging to stderr."""
- log.removeHandler(stderrHandler)
diff -r cc303cdf8809 -r 83a882b3d807 tools/python/xen/xend/XendRoot.py
--- a/tools/python/xen/xend/XendRoot.py Fri Mar 10 10:05:59 2006
+++ b/tools/python/xen/xend/XendRoot.py Fri Mar 10 10:38:15 2006
@@ -102,15 +102,14 @@
"""
print >>sys.stderr, "xend [ERROR]", fmt % args
+
def configure(self):
self.set_config()
- logfile = self.get_config_value("logfile", self.logfile_default)
- loglevel = self.get_config_value("loglevel", self.loglevel_default)
- XendLogging.init(logfile, level = loglevel)
-
- from xen.xend.server import params
- if params.XEND_DEBUG:
- XendLogging.addLogStderr()
+ XendLogging.init(self.get_config_value("logfile",
+ self.logfile_default),
+ self.get_config_value("loglevel",
+ self.loglevel_default))
+
def set_config(self):
"""If the config file exists, read it. If not, ignore it.
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|