[openlmi-tools/f20] fix unset logging handlers
Peter Hatina
phatina at fedoraproject.org
Wed Jul 16 12:54:40 UTC 2014
commit deeea269620d66149589ceb47632fb2c39e2921d
Author: Peter Hatina <phatina at redhat.com>
Date: Wed Jul 16 14:00:48 2014 +0200
fix unset logging handlers
openlmi-tools-01-logging.patch | 262 ++++++++++++++++++++++++++++++++++++++++
openlmi-tools.spec | 8 +-
2 files changed, 269 insertions(+), 1 deletions(-)
---
diff --git a/openlmi-tools-01-logging.patch b/openlmi-tools-01-logging.patch
new file mode 100644
index 0000000..175cf06
--- /dev/null
+++ b/openlmi-tools-01-logging.patch
@@ -0,0 +1,262 @@
+diff --git a/cli/lmi/shell/LMIConnection.py b/cli/lmi/shell/LMIConnection.py
+index b708551..ac126b1 100644
+--- a/cli/lmi/shell/LMIConnection.py
++++ b/cli/lmi/shell/LMIConnection.py
+@@ -35,6 +35,8 @@ from LMISubscription import LMISubscription
+ from LMIExceptions import LMIIndicationError
+ from LMIExceptions import LMINamespaceNotFound
+
++from LMIShellLogger import lmi_get_logger
++
+ from LMIUtil import lmi_raise_or_dump_exception
+ from LMIUtil import lmi_get_use_exceptions
+ from LMIUtil import lmi_set_use_exceptions
+@@ -50,6 +52,8 @@ LOCALHOST_VARIANTS = (
+ "::1",
+ )
+
++logger = lmi_get_logger()
++
+ def __lmi_raw_input(prompt, use_echo=True):
+ """
+ Reads a string from the standard input.
+@@ -140,7 +144,6 @@ def connect(uri, username="", password="", **kwargs):
+ if kwargs:
+ raise TypeError("connect() got an unexpected keyword arguments: %s" % ", ".join(kwargs.keys()))
+
+- logger = logging.getLogger(__name__)
+ connection = None
+
+ # If we are running as root and the scheme has not been explicitly set,
+diff --git a/cli/lmi/shell/LMIConstantValues.py b/cli/lmi/shell/LMIConstantValues.py
+index f2550f4..fd5514c 100644
+--- a/cli/lmi/shell/LMIConstantValues.py
++++ b/cli/lmi/shell/LMIConstantValues.py
+@@ -18,8 +18,11 @@ import logging
+ import sys
+ import re
+
++from LMIShellLogger import lmi_get_logger
+ from LMIUtil import lmi_cast_to_lmi
+
++logger = lmi_get_logger()
++
+ class LMIConstantValues(object):
+ """
+ Abstract class for constant value objects.
+@@ -34,7 +37,6 @@ class LMIConstantValues(object):
+ __metaclass__ = abc.ABCMeta
+
+ def __init__(self, cim_obj, cast_type):
+- logger = logging.getLogger(__name__)
+ items = zip(
+ cim_obj.qualifiers["Values"].value,
+ cim_obj.qualifiers["ValueMap"].value)
+diff --git a/cli/lmi/shell/LMIShellLogger.py b/cli/lmi/shell/LMIShellLogger.py
+new file mode 100644
+index 0000000..932d8ec
+--- /dev/null
++++ b/cli/lmi/shell/LMIShellLogger.py
+@@ -0,0 +1,152 @@
++# Copyright (C) 2012-2014 Peter Hatina <phatina at redhat.com>
++#
++# This program is free software; you can redistribute it and/or
++# modify it under the terms of the GNU General Public License
++# as published by the Free Software Foundation; either version 2
++# of the License, or (at your option) any later version.
++#
++# This program is distributed in the hope that it will be useful,
++# but WITHOUT ANY WARRANTY; without even the implied warranty of
++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
++# GNU General Public License for more details.
++#
++# You should have received a copy of the GNU General Public License
++# along with this program; if not, see <http://www.gnu.org/licenses/>.
++
++import logging
++import sys
++
++from lmi.shell.LMIShellOptions import LMIShellOptions
++
++
++class LMIShellLogger(logging.Logger):
++ """
++ LMIShell's logger with queueing capability.
++ """
++ def __init__(self, name, level=logging.NOTSET):
++ # Due to Python2.6 compatibility, we call superclass c-tor in this way.
++ logging.Logger.__init__(self, name, level)
++ self.queue = []
++
++ def _log(self, level, msg, args, exc_info=None, extra=None):
++ if logging._srcfile:
++ try:
++ fn, lno, func = self.findCaller()
++ except ValueError:
++ fn, lno, func = "(unknown file)", 0, "(unknown function)"
++ else:
++ fn, lno, func = "(unknown file)", 0, "(unknown function)"
++ if exc_info:
++ if not isinstance(exc_info, tuple):
++ exc_info = sys.exc_info()
++
++ record = self.makeRecord(
++ self.name, level, fn, lno, msg, args, exc_info, func, extra)
++ if self.isEnabledFor(level):
++ self.handle(record)
++ else:
++ self.queue.append(record)
++
++ def setLevel(self, level):
++ """
++ Sets a logging level of this handler. If there are any log records
++ stored in internal queue, they are also handled.
++
++ :param int level: logging level
++ """
++ logging.Logger.setLevel(self, level)
++ self.processQueue()
++
++ def processQueue(self):
++ """
++ Logs all enabled log records stored in internal queue.
++ """
++ # Handle all enabled log records.
++ for r in self.queue:
++ if not self.isEnabledFor(r.levelno):
++ continue
++ self.handle(r)
++
++ # Remove all handled records.
++ self.queue = filter(
++ lambda r: not self.isEnabledFor(r.levelno),
++ self.queue)
++
++ def debug(self, msg, *args, **kwargs):
++ """
++ Log a message with severity 'DEBUG'.
++ """
++ self._log(logging.DEBUG, msg, args, **kwargs)
++
++ def critical(self, msg, *args, **kwargs):
++ """
++ Log a message with severity 'CRITICAL'.
++ """
++ self._log(logging.CRITICAL, msg, args, **kwargs)
++
++ def error(self, msg, *args, **kwargs):
++ """
++ Log a message with severity 'ERROR'.
++ """
++ self._log(logging.ERROR, msg, args, **kwargs)
++
++ def exception(self, msg, *args, **kwargs):
++ """
++ Log a message with severity 'ERROR' also with exception information.
++ """
++ kwargs["exc_info"] = 1
++ self.error(msg, args, **kwargs)
++
++ def info(self, msg, *args, **kwargs):
++ """
++ Log a message with severity 'INFO'.
++ """
++ self._log(logging.INFO, msg, args, **kwargs)
++
++ def warning(self, msg, *args, **kwargs):
++ """
++ Log a message with severity 'WARNING'.
++ """
++ self._log(logging.WARNING, msg, args, **kwargs)
++
++logging.setLoggerClass(LMIShellLogger)
++
++
++def lmi_init_logger():
++ """
++ Initializes LMIShell's logging.
++ """
++ logging.basicConfig(format='%(levelname)s: %(message)s')
++
++
++def lmi_get_logger():
++ """
++ Returns LMIShell's logger.
++
++ :returns: logger
++ """
++ return logging.getLogger("lmishell")
++
++
++def lmi_setup_logger(log_options):
++ """
++ Sets logging level.
++
++ :param int log_options: level defined in :py:class:`.LMIShellOptions`
++ """
++ logger = lmi_get_logger()
++ if log_options == LMIShellOptions._LOG_MORE_VERBOSE:
++ # Print out all the log messages to stderr stream
++ logger.setLevel(logging.DEBUG)
++ elif log_options == LMIShellOptions._LOG_VERBOSE:
++ # Print out only a set of log messages to stderr stream
++ logger.setLevel(logging.INFO)
++ elif log_options == LMIShellOptions._LOG_QUIET:
++ # Quiet flag seen, drop all the log messages
++ handlers = logger.handlers
++ for handler in handlers:
++ logger.removeHandler(handler)
++ logger.addHandler(logging.NullHandler())
++ else:
++ # By default, print error messages to stderr stream
++ logger.setLevel(logging.ERROR)
+diff --git a/cli/lmi/shell/__init__.py b/cli/lmi/shell/__init__.py
+index cbf3479..f66e38e 100644
+--- a/cli/lmi/shell/__init__.py
++++ b/cli/lmi/shell/__init__.py
+@@ -17,6 +17,10 @@
+ LMIShell
+ """
+
++# Setup logging format
++from lmi.shell.LMIShellLogger import lmi_init_logger
++lmi_init_logger()
++
+ from LMIShellVersion import __version__
+
+ from LMIExceptions import *
+diff --git a/cli/lmishell b/cli/lmishell
+index 0b41f6b..dec8c8e 100755
+--- a/cli/lmishell
++++ b/cli/lmishell
+@@ -19,26 +19,13 @@ import logging
+
+ from lmi.shell import LMIConsole
+ from lmi.shell import LMIShellOptions
++from lmi.shell.LMIShellLogger import lmi_setup_logger
+
+ if __name__ == "__main__":
+ options = LMIShellOptions(sys.argv)
+- logging.basicConfig(format='%(levelname)s: %(message)s')
+- logger = logging.getLogger("")
+- if options.log == LMIShellOptions._LOG_MORE_VERBOSE:
+- # Print out all the log messages to stderr stream
+- logger.setLevel(logging.DEBUG)
+- elif options.log == LMIShellOptions._LOG_VERBOSE:
+- # Print out only a set of log messages to stderr stream
+- logger.setLevel(logging.INFO)
+- elif options.log == LMIShellOptions._LOG_QUIET:
+- # Quiet flag seen, drop all the log messages
+- handlers = logger.handlers
+- for handler in handlers:
+- logger.removeHandler(handler)
+- logger.addHandler(logging.NullHandler())
+- else:
+- # By default, print error messages to stderr stream
+- logger.setLevel(logging.ERROR)
++
++ # Setup logging
++ lmi_setup_logger(options.log)
+
+ console = LMIConsole(options.cwd_first_in_path)
+ console.set_verify_server_certificate(options.verify_server_cert)
diff --git a/openlmi-tools.spec b/openlmi-tools.spec
index f5336c0..24ac307 100644
--- a/openlmi-tools.spec
+++ b/openlmi-tools.spec
@@ -1,11 +1,12 @@
Name: openlmi-tools
Version: 0.9.2
-Release: 1%{?dist}
+Release: 2%{?dist}
Summary: Set of CLI tools for Openlmi providers
License: GPLv2+
URL: http://fedorahosted.org/openlmi
Source0: http://fedorahosted.org/released/openlmi-tools/%{name}-%{version}.tar.gz
+Patch0: openlmi-tools-01-logging.patch
BuildArch: noarch
BuildRequires: automake
@@ -42,6 +43,7 @@ Group: Documentation
%prep
%setup -q
+%patch0 -p1 -b .logging
%build
make
@@ -114,6 +116,10 @@ install -m 644 cli/completion/_lmishell $zsh_comp_dir
%{_docdir}/%{name}-%{version}/html
%changelog
+* Wed Jul 16 2014 Peter Hatina <phatina at redhat.com> - 0.9.2-2
+- fix unset logging handlers
+- Resolves: rhbz#1119747
+
* Mon Jun 30 2014 Peter Hatina <phatina at redhat.com> - 0.9.2-1
- upgrade to 0.9.2
More information about the scm-commits
mailing list