[PATCH] Add a new log level 'lock' for _yum_lock
Vratislav Podzimek
vpodzime at redhat.com
Mon Jun 16 08:16:39 UTC 2014
On Fri, 2014-06-13 at 15:18 -0700, Brian C. Lane wrote:
> It is useful to log debug output from packaging without the yum_lock
> logging. With this change yum_lock logging is only turned on with
> inst.loglevel=lock
>
> inst.debug, inst.updates, and inst.loglevel=debug now only turn on debug
> logging for packaging.log with no yum_lock output.
> ---
> anaconda | 15 ++++++---------
> pyanaconda/anaconda_log.py | 11 ++++++++---
> pyanaconda/constants.py | 3 +++
> pyanaconda/packaging/yumpayload.py | 9 +++++----
> 4 files changed, 22 insertions(+), 16 deletions(-)
>
> diff --git a/anaconda b/anaconda
> index 1be9eda..513965d 100755
> --- a/anaconda
> +++ b/anaconda
> @@ -379,22 +379,19 @@ def setupEnvironment():
> del os.environ["LD_PRELOAD"]
>
> def setupLoggingFromOpts(options):
> - want_yum_lock_logs = False
> - if options.debug or options.updateSrc:
> - # debugging means debug logging
> + if (options.debug or options.updateSrc) and not options.loglevel:
> + # debugging means debug logging if an explicit level hasn't been st
> options.loglevel = "debug"
> - want_yum_lock_logs = options.debug
>
> if options.loglevel and options.loglevel in anaconda_log.logLevelMap:
> - level = anaconda_log.logLevelMap[opts.loglevel]
> + log.info("Switching logging level to %s", options.loglevel)
> + level = anaconda_log.logLevelMap[options.loglevel]
> anaconda_log.logger.tty_loglevel = level
> anaconda_log.setHandlersLevel(log, level)
> storage_log = logging.getLogger("storage")
> anaconda_log.setHandlersLevel(storage_log, level)
> -
> - if options.loglevel != "debug" or want_yum_lock_logs:
> - packaging_log = logging.getLogger("packaging")
> - anaconda_log.setHandlersLevel(packaging_log, level)
> + packaging_log = logging.getLogger("packaging")
> + anaconda_log.setHandlersLevel(packaging_log, level)
>
> if options.syslog:
> anaconda_log.logger.updateRemote(options.syslog)
> diff --git a/pyanaconda/anaconda_log.py b/pyanaconda/anaconda_log.py
> index 8105835..1a48ea9 100644
> --- a/pyanaconda/anaconda_log.py
> +++ b/pyanaconda/anaconda_log.py
> @@ -30,6 +30,7 @@ import types
> import warnings
>
> from pyanaconda.flags import flags
> +from pyanaconda.constants import LOGLVL_LOCK
>
> DEFAULT_TTY_LEVEL = logging.INFO
> ENTRY_FORMAT = "%(asctime)s,%(msecs)03d %(levelname)s %(name)s: %(message)s"
> @@ -49,8 +50,11 @@ ANACONDA_SYSLOG_FACILITY = SysLogHandler.LOG_LOCAL1
> from threading import Lock
> program_log_lock = Lock()
>
> -logLevelMap = {"debug": logging.DEBUG, "info": logging.INFO,
> - "warning": logging.WARNING, "error": logging.ERROR,
> +logLevelMap = {"lock": LOGLVL_LOCK,
> + "debug": logging.DEBUG,
> + "info": logging.INFO,
> + "warning": logging.WARNING,
> + "error": logging.ERROR,
> "critical": logging.CRITICAL}
>
> # sets autoSetLevel for the given handler
> @@ -87,6 +91,7 @@ class AnacondaLog:
> logging.addLevelName(logging.WARNING, "WARN")
> logging.addLevelName(logging.ERROR, "ERR")
> logging.addLevelName(logging.CRITICAL, "CRIT")
> + logging.addLevelName(LOGLVL_LOCK, "LOCK")
>
> # Create the base of the logger hierarchy.
> self.anaconda_logger = logging.getLogger("anaconda")
> @@ -123,7 +128,7 @@ class AnacondaLog:
>
> # Create the packaging logger.
> packaging_logger = logging.getLogger("packaging")
> - packaging_logger.setLevel(logging.DEBUG)
> + packaging_logger.setLevel(LOGLVL_LOCK)
> self.addFileHandler(PACKAGING_LOG_FILE, packaging_logger,
> minLevel=logging.INFO,
> autoLevel=True)
> diff --git a/pyanaconda/constants.py b/pyanaconda/constants.py
> index db786b5..4f9b64a 100644
> --- a/pyanaconda/constants.py
> +++ b/pyanaconda/constants.py
> @@ -166,3 +166,6 @@ TAR_SUFFIX = (".tar", ".tbz", ".tgz", ".txz", ".tar.bz2", "tar.gz", "tar.xz")
> CMDLINE_APPEND = ["modprobe.blacklist"]
>
> DEFAULT_AUTOPART_TYPE = AUTOPART_TYPE_LVM
> +
> +import logging
> +LOGLVL_LOCK = logging.DEBUG-1
Please add spaces around the '-' operator.
> diff --git a/pyanaconda/packaging/yumpayload.py b/pyanaconda/packaging/yumpayload.py
> index 760fa02..c05d36a 100644
> --- a/pyanaconda/packaging/yumpayload.py
> +++ b/pyanaconda/packaging/yumpayload.py
> @@ -63,7 +63,8 @@ except ImportError:
> log.error("import of yum failed")
> yum = None
>
> -from pyanaconda.constants import BASE_REPO_NAME, DRACUT_ISODIR, INSTALL_TREE, ISO_DIR, MOUNT_DIR
> +from pyanaconda.constants import BASE_REPO_NAME, DRACUT_ISODIR, INSTALL_TREE, ISO_DIR, MOUNT_DIR, \
> + LOGLVL_LOCK
> from pyanaconda.flags import flags
>
> from pyanaconda import iutil
> @@ -101,16 +102,16 @@ class YumLock(object):
> frame = inspect.stack()[2]
> threadName = threading.currentThread().name
>
> - log.debug("about to acquire _yum_lock for %s at %s:%s (%s)", threadName, frame[1], frame[2], frame[3])
> + log.log(LOGLVL_LOCK, "about to acquire _yum_lock for %s at %s:%s (%s)", threadName, frame[1], frame[2], frame[3])
> _private_yum_lock.acquire()
> - log.debug("have _yum_lock for %s", threadName)
> + log.log(LOGLVL_LOCK, "have _yum_lock for %s", threadName)
> return _private_yum_lock
>
> def __exit__(self, exc_type, exc_val, exc_tb):
> _private_yum_lock.release()
>
> if not isFinal:
> - log.debug("gave up _yum_lock for %s", threading.currentThread().name)
> + log.log(LOGLVL_LOCK, "gave up _yum_lock for %s", threading.currentThread().name)
>
> def refresh_base_repo(cond_fn=None):
> """
It is non-standard log level and anybody outside of the team will hardly
come up with such "magic", but I believe we are the only readers of
those lock-log messages so ACK.
--
Vratislav Podzimek
Anaconda Rider | RHCE | Red Hat, Inc. | Brno - Czech Republic
More information about the anaconda-patches
mailing list