--- anaconda | 6 +++--- anaconda_log.py | 31 ++++++++++++------------------- kickstart.py | 4 ++-- yuminstall.py | 3 +++ 4 files changed, 20 insertions(+), 24 deletions(-) diff --git a/anaconda b/anaconda index 78e5fd1..b87c58a 100755 --- a/anaconda +++ b/anaconda @@ -302,8 +302,8 @@ def setupEnvironment(): def setupLoggingFromOpts(opts): if opts.loglevel and logLevelMap.has_key(opts.loglevel): level = logLevelMap[opts.loglevel] - log.setHandlersLevel(level) - storage.storage_log.logger.setHandlersLevel(level) + setHandlersLevel(log, level) + setHandlersLevel(storage.storage_log.logger, level) if opts.syslog: if opts.syslog.find(":") != -1: @@ -573,7 +573,7 @@ if __name__ == "__main__": # Set up logging as early as possible. import logging - from anaconda_log import logger, logLevelMap + from anaconda_log import logger, logLevelMap, setHandlersLevel log = logging.getLogger("anaconda") stdoutLog = logging.getLogger("anaconda.stdout") diff --git a/anaconda_log.py b/anaconda_log.py index 3be4e6a..a6363f6 100644 --- a/anaconda_log.py +++ b/anaconda_log.py @@ -38,20 +38,14 @@ logLevelMap = {"debug": logging.DEBUG, "info": logging.INFO, "warning": logging.WARNING, "error": logging.ERROR, "critical": logging.CRITICAL} -# Base class for logger instances. This is what will be created any time -# someone calls logging.getLogger("whatever"). We need this class to -# provide the setHandlersLevel function. -class LoggerClass(logging.Logger): - # Set the level of all handlers attached to a logger, except those - # with the autoSetLevel=False attribute. - def setHandlersLevel(self, level): - map(lambda hdlr: hdlr.setLevel(level), - filter (lambda hdlr: hasattr(hdlr, "autoSetLevel") and hdlr.autoSetLevel, self.handlers)) +# sets autoSetLevel for the given handler +def autoSetLevel(handler, value): + handler.autoSetLevel = value - # Specialized addHandler that also adds the autoSetLevel attribute. - def addHandler(self, hdlr, autoSetLevel=True): - setattr(hdlr, "autoSetLevel", autoSetLevel) - logging.Logger.addHandler(self, hdlr) +# all handlers of given logger with autoSetLevel == True are set to level +def setHandlersLevel(logger, level): + map(lambda hdlr: hdlr.setLevel(level), + filter (lambda hdlr: hasattr(hdlr, "autoSetLevel") and hdlr.autoSetLevel, logger.handlers)) class AnacondaLog: def __init__ (self, minLevel=DEFAULT_LEVEL): @@ -59,13 +53,13 @@ class AnacondaLog: self.logger = logging.getLogger("anaconda") self.logger.setLevel(logging.DEBUG) self.addFileHandler(MAIN_LOG_FILE, self.logger, - autoSetLevel=False, minLevel=logging.DEBUG) + autoLevel=False, minLevel=logging.DEBUG) # External program output log program_logger = logging.getLogger("program") program_logger.setLevel(logging.DEBUG) self.addFileHandler(PROGRAM_LOG_FILE, program_logger, - autoSetLevel=False, minLevel=logging.DEBUG) + autoLevel=False, minLevel=logging.DEBUG) # Create a second logger for just the stuff we want to dup on # stdout. Anything written here will also get passed up to the @@ -81,7 +75,7 @@ class AnacondaLog: # Add a simple handler - file or stream, depending on what we're given. def addFileHandler (self, file, addToLogger, minLevel=DEFAULT_LEVEL, fmtStr=DEFAULT_ENTRY_FORMAT, - autoSetLevel=True): + autoLevel=True): if isinstance(file, types.StringTypes): logfileHandler = logging.FileHandler(file) else: @@ -89,7 +83,8 @@ class AnacondaLog: logfileHandler.setLevel(minLevel) logfileHandler.setFormatter(logging.Formatter(fmtStr, DEFAULT_DATE_FORMAT)) - addToLogger.addHandler(logfileHandler, autoSetLevel=autoSetLevel) + autoSetLevel(logfileHandler, autoLevel) + addToLogger.addHandler(logfileHandler) # Add another logger to the hierarchy. For best results, make sure # name falls under anaconda in the tree. @@ -106,6 +101,4 @@ class AnacondaLog: syslogHandler.setFormatter(fmt) logger.addHandler(syslogHandler) -# Set base class for logger instances. -logging.setLoggerClass(LoggerClass) logger = AnacondaLog() diff --git a/kickstart.py b/kickstart.py index bd4d05c..2f578d3 100644 --- a/kickstart.py +++ b/kickstart.py @@ -55,7 +55,7 @@ _ = lambda x: gettext.ldgettext("anaconda", x) import logging log = logging.getLogger("anaconda") -from anaconda_log import logger, logLevelMap +from anaconda_log import logger, logLevelMap, setHandlersLevel class AnacondaKSScript(Script): def run(self, chroot, serial, intf = None): @@ -516,7 +516,7 @@ class LogVolData(commands.logvol.F12_LogVolData): class Logging(commands.logging.FC6_Logging): def execute(self, anaconda): - log.setHandlersLevel(logLevelMap[self.level]) + setHandlersLevel(log, logLevelMap[self.level]) if self.host != "" and self.port != "": logger.addSysLogHandler(log, self.host, port=int(self.port)) diff --git a/yuminstall.py b/yuminstall.py index 7db91cf..7a1f0c5 100644 --- a/yuminstall.py +++ b/yuminstall.py @@ -33,6 +33,8 @@ import tempfile import itertools import re + +import anaconda_log import rpm import rpmUtils import urlgrabber.progress @@ -629,6 +631,7 @@ class AnacondaYum(YumSorter): logger.propagate = False logger.setLevel(yum.logginglevels.INFO_2) logger.addHandler(file_handler) + anaconda_log.autoSetLevel(tty3_handler, True) logger.addHandler(tty3_handler) # XXX filelogger is set in setFileLog - do we or user want it? -- 1.6.2.5 _______________________________________________ Anaconda-devel-list mailing list Anaconda-devel-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/anaconda-devel-list