summaryrefslogtreecommitdiffstats
path: root/src/software
diff options
context:
space:
mode:
authorMichal Minar <miminar@redhat.com>2013-07-07 18:12:15 +0200
committerMichal Minar <miminar@redhat.com>2013-07-23 13:52:34 +0200
commit92dc6ef51b693a6f74f5252b1828b2fd82289d15 (patch)
treecbdc004002702ce051ad119669bf2b8a880f2ea5 /src/software
parent5523514682e86e97ad0389585e4dcb2d2b244850 (diff)
downloadopenlmi-providers-92dc6ef51b693a6f74f5252b1828b2fd82289d15.tar.gz
openlmi-providers-92dc6ef51b693a6f74f5252b1828b2fd82289d15.tar.xz
openlmi-providers-92dc6ef51b693a6f74f5252b1828b2fd82289d15.zip
software: disable logging of separate process
separated process can not use logging facilities of cimom logging of YumWorker process made configurable
Diffstat (limited to 'src/software')
-rw-r--r--src/software/lmi/software/yumdb/__init__.py45
-rw-r--r--src/software/lmi/software/yumdb/process.py7
-rw-r--r--src/software/lmi/software/yumdb/util.py105
3 files changed, 77 insertions, 80 deletions
diff --git a/src/software/lmi/software/yumdb/__init__.py b/src/software/lmi/software/yumdb/__init__.py
index 4a7a5f6..b1e26d2 100644
--- a/src/software/lmi/software/yumdb/__init__.py
+++ b/src/software/lmi/software/yumdb/__init__.py
@@ -54,50 +54,6 @@ from lmi.software.yumdb.packageinfo import PackageInfo
from lmi.software.yumdb.process import YumWorker
from lmi.software.yumdb.repository import Repository
-# Maximum time in seconds to wait for a job to accomplish.
-# If timeout expires, spawned process is checked (it might
-# be possibly killed) and is respawned in case it's dead.
-MAX_JOB_WAIT_TIME = 30
-
-# TODO: make this a configuration file
-# 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
- "default": {
- "()": "lmi.software.util.cmpi_logging.DispatchingFormatter",
- "formatters" : {
- "lmi.software.util.cmpi_logging.trace_function_or_method":
- "%(asctime)s %(levelname)s:%(message)s"
- },
- "default" : "%(asctime)s %(levelname)s:%(module)s:"
- "%(funcName)s:%(lineno)d - %(message)s"
- },
- },
- "handlers": {
- "file" : {
- "class" : "logging.handlers.RotatingFileHandler",
- "filename" : "/var/tmp/YumWorker.log",
- "level" : "DEBUG",
- "formatter": "default",
- },
- },
- "loggers" : {
- "root": {
- "level": "DEBUG",
- "handlers" : ["file"]
- },
- "lmi.software.yumdb": {
- "level" : "DEBUG",
- "handlers" : ["file"],
- "propagate" : False,
- },
- }
-}
-
LOG = cmpi_logging.get_logger(__name__)
# *****************************************************************************
@@ -388,7 +344,6 @@ class YumDB(singletonmixin.Singleton):
self._process = YumWorker(uplink, downlink,
indication_manager=IndicationManager.get_instance(),
yum_kwargs=self._yum_kwargs)
- #logging_config=YUM_WORKER_DEBUG_LOGGING_CONFIG)
self._process.start()
LOG().trace_info("YumWorker started with pid=%s", self._process.pid)
return self._process
diff --git a/src/software/lmi/software/yumdb/process.py b/src/software/lmi/software/yumdb/process.py
index 238d661..5686511 100644
--- a/src/software/lmi/software/yumdb/process.py
+++ b/src/software/lmi/software/yumdb/process.py
@@ -212,8 +212,7 @@ class YumWorker(Process):
queue_in,
queue_out,
indication_manager,
- yum_kwargs=None,
- logging_config=None):
+ yum_kwargs=None):
Process.__init__(self, name="YumWorker")
self._jobmgr = JobManager(queue_in, queue_out, indication_manager)
self._session_level = 0
@@ -229,7 +228,6 @@ class YumWorker(Process):
# contains (repoid, time_stamp_of_config_file)
# plus (/repos/dir, ...) for each repo config directory
self._repodir_mtimes = {}
- self._logging_config = logging_config
# *************************************************************************
# Private methods
@@ -895,8 +893,7 @@ class YumWorker(Process):
"""
Thread's entry point. After initial setup it calls _main_loop().
"""
- if self._logging_config is not None:
- setup_logging(self._logging_config)
+ setup_logging()
global LOG
LOG = logging.getLogger(__name__)
LOG.info("running as pid=%d", self.pid)
diff --git a/src/software/lmi/software/yumdb/util.py b/src/software/lmi/software/yumdb/util.py
index ec5f41d..7c3d364 100644
--- a/src/software/lmi/software/yumdb/util.py
+++ b/src/software/lmi/software/yumdb/util.py
@@ -23,43 +23,88 @@
Common utilities meant to be used only be ``yumdb`` subpackage.
"""
-from itertools import chain
-import inspect
import logging
-import os
-
from lmi.software.util import cmpi_logging
+from lmi.software.util import Configuration
-def setup_logging(config):
+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
+ "default": {
+ "()": "lmi.software.util.cmpi_logging.DispatchingFormatter",
+ "formatters" : {
+ "lmi.software.util.cmpi_logging.trace_function_or_method":
+ "%(asctime)s %(levelname)s:%(message)s"
+ },
+ "default" : "%(asctime)s %(levelname)s:%(module)s:"
+ "%(funcName)s:%(lineno)d - %(message)s"
+ },
+ },
+ "handlers": {
+ "file" : {
+ "class" : "logging.FileHandler",
+ "filename" : "/var/tmp/YumWorker.log",
+ "level" : "DEBUG",
+ "formatter": "default",
+ },
+ },
+ "root": {
+ "level": "DEBUG",
+ "handlers" : ["file"]
+ },
+}
+
+DISABLED_LOGGING_CONFIG = {
+ 'version' : 1,
+ 'disable_existing_loggers' : True,
+ 'handlers': {
+ 'null' : {
+ 'class': 'logging.FileHandler',
+ 'level': 'CRITICAL',
+ 'filename': '/dev/null'
+ }
+ },
+ 'root' : {
+ 'level': 'CRITICAL',
+ 'handlers' : ['null'],
+ }
+}
+
+def setup_logging():
"""
This is meant to be used by ``YumWorker`` process to setup logging
independent of what providers are using. Unfortunately ``YumWorker``
can not use the same facilities as the rest of program, because
logging is done through *broker*.
"""
- try:
- logging.config.dictConfig(config)
- cmpi_logging.logger = logging.getLogger('lmi.software.yumdb')
- except Exception: #pylint: disable=W0703
- # logging is not set up but client expects us to work
- # 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
- }
- }
- })
-
+ config = Configuration.get_instance()
+ cp = config.config
+ logging_setup = False
+ if cp.has_option('YumWorkerLog', 'file_config'):
+ try:
+ file_path = config.file_path('YumWorkerLog', 'file_config')
+ logging.config.fileConfig(file_path)
+ logging_setup = True
+ except Exception:
+ pass
+ if logging_setup is False:
+ out = config.get_safe('YumWorkerLog', 'output_file')
+ if out is not None:
+ try:
+ defaults = DEBUG_LOGGING_CONFIG.copy()
+ defaults["handlers"]["file"]["filename"] = out
+ level = config.get_safe('YumWorkerLog', 'level')
+ level = cmpi_logging.LOGGING_LEVELS[level.lower()]
+ defaults["handlers"]["file"]["level"] = level
+ defaults["root"]["level"] = level
+ logging.config.dictConfig(defaults)
+ logging_setup = True
+ except Exception:
+ pass
+ if logging_setup is False:
+ # disable logging completely
+ logging.config.dictConfig(DISABLED_LOGGING_CONFIG)