From fd853469a2e2a34296f5088277c28edacdbe40f7 Mon Sep 17 00:00:00 2001 From: Michal Minar Date: Fri, 5 Apr 2013 11:58:19 +0200 Subject: logging improvements this relates mostly to YumWorker separated process that does not use cmpi_logging --- src/software/openlmi/software/cimom_entry.py | 1 + src/software/openlmi/software/yumdb/__init__.py | 3 ++- src/software/openlmi/software/yumdb/util.py | 35 ++++++++++++++++++++----- 3 files changed, 31 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/software/openlmi/software/cimom_entry.py b/src/software/openlmi/software/cimom_entry.py index eaa7b0c..ad944c8 100644 --- a/src/software/openlmi/software/cimom_entry.py +++ b/src/software/openlmi/software/cimom_entry.py @@ -70,6 +70,7 @@ def get_providers(env): """ @return mapping of provider names to corresponding provider instances. """ + cmpi_logging.LogManager.LOGGER_NAME = 'openlmi.software' cmpi_logging.LogManager(env) # jobmanager does not understand CIM models, give it a way to transform diff --git a/src/software/openlmi/software/yumdb/__init__.py b/src/software/openlmi/software/yumdb/__init__.py index bbf2364..04f2191 100644 --- a/src/software/openlmi/software/yumdb/__init__.py +++ b/src/software/openlmi/software/yumdb/__init__.py @@ -63,6 +63,7 @@ MAX_JOB_WAIT_TIME = 30 # this may be used as an argument to YumWorker to setup logging YUM_WORKER_DEBUG_LOGGING_CONFIG = { "version" : 1, + 'disable_existing_loggers' : True, "formatters": { # this is a message format for logging function/method calls # it's manually set up in YumWorker's init method @@ -86,7 +87,7 @@ YUM_WORKER_DEBUG_LOGGING_CONFIG = { }, "loggers" : { "root": { - "level": "ERROR", + "level": "DEBUG", "handlers" : ["file"] }, "openlmi.software.yumdb": { diff --git a/src/software/openlmi/software/yumdb/util.py b/src/software/openlmi/software/yumdb/util.py index bd2a0ca..a1ab338 100644 --- a/src/software/openlmi/software/yumdb/util.py +++ b/src/software/openlmi/software/yumdb/util.py @@ -28,7 +28,7 @@ import inspect import logging import os -from openlmi.software.yumdb import errors +from openlmi.common import cmpi_logging class DispatchingFormatter: """ @@ -117,11 +117,12 @@ def trace_function(func): logger.debug("%(caller_file)s:%(caller_lineno)d - %(action)s" " %(module)s:%(func)s:%(lineno)d", logargs) except Exception as exc: - logargs['action'] = 'exiting' - logargs['error'] = str(exc) - logger.debug("%(caller_file)s:%(caller_lineno)d - %(action)s" - " %(module)s:%(func)s:%(lineno)d with error: %(error)s", - logargs) + if logger.isEnabledFor(logging.DEBUG): + logargs['action'] = 'exiting' + logargs['error'] = str(exc) + logger.debug("%(caller_file)s:%(caller_lineno)d - %(action)s" + " %(module)s:%(func)s:%(lineno)d with error: %(error)s", + logargs) raise return result @@ -136,7 +137,27 @@ def setup_logging(config): """ try: logging.config.dictConfig(config) + cmpi_logging.logger = logging.getLogger('openlmi.software.yumdb') except Exception: #pylint: disable=W0703 # logging is not set up but client expects us to work - pass + # all messages are dumped to /dev/null + logging.config.dictConfig({ + 'version' : 1, + 'disable_existing_loggers' : True, + 'handlers': { + 'null' : { + 'class': 'logging.handlers.FileHandler', + 'level': 'CRITICAL', + 'filename': '/dev/null' + } + }, + 'loggers' : { + 'root' : { + 'level': 'CRITICAL', + 'handlers' : ['null'], + 'propagate' : False + } + } + }) + -- cgit