Extract logging config into a helper function

It's an error to have a library class set up logging output for you, as
this will prevent a consumer from doing what they need to do with their
logging config.

However, for simple scripts, the complexity of what needs to be done for
"normal" operation is a bit onerous.

Create a simple helper function that a user can run to set up the two
most common types of logging expected for simple scripts.

Change-Id: I81ef597712ff885d95194c6e29a45a1b2e7f86b9
This commit is contained in:
Monty Taylor 2015-06-05 10:58:57 -04:00
parent 18cf7c2ccb
commit 2c926e618c

View File

@ -49,6 +49,7 @@ from shade import task_manager
from shade import _tasks
from shade import _utils
__version__ = pbr.version.VersionInfo('shade').version_string()
OBJECT_MD5_KEY = 'x-object-meta-x-shade-md5'
OBJECT_SHA256_KEY = 'x-object-meta-x-shade-sha256'
@ -88,6 +89,16 @@ def valid_kwargs(*valid_args):
return func_wrapper
def simple_logging(debug=False):
if debug:
log_level = logging.DEBUG
else:
log_level = logging.INFO
log = logging.getLogger('shade')
log.addHandler(logging.StreamHandler())
log.setLevel(log_level)
def openstack_clouds(config=None, debug=False):
if not config:
config = os_client_config.OpenStackConfig()
@ -213,8 +224,7 @@ class OpenStackCloud(object):
:param string cert: A path to a client certificate to pass to requests.
(optional)
:param string key: A path to a client key to pass to requests. (optional)
:param bool debug: Enable or disable debug logging (optional, defaults to
False)
:param bool debug: Deprecated and unused parameter.
:param int cache_interval: How long to cache items fetched from the cloud.
Value will be passed to dogpile.cache. None
means do not cache at all.
@ -247,6 +257,8 @@ class OpenStackCloud(object):
image_api_use_tasks=False,
**kwargs):
self.log = logging.getLogger('shade')
self.name = cloud
self.auth = auth
self.region_name = region_name
@ -290,13 +302,6 @@ class OpenStackCloud(object):
self._swift_client = None
self._trove_client = None
self.log = logging.getLogger('shade')
log_level = logging.INFO
if debug:
log_level = logging.DEBUG
self.log.setLevel(log_level)
self.log.addHandler(logging.StreamHandler())
def _make_cache_key(self, namespace, fn):
fname = fn.__name__
if namespace is None:
@ -348,11 +353,6 @@ class OpenStackCloud(object):
@property
def keystone_session(self):
if self._keystone_session is None:
# keystoneclient does crazy things with logging that are
# none of them interesting
keystone_logging = logging.getLogger('keystoneclient')
keystone_logging.addHandler(logging.NullHandler())
try:
auth_plugin = ksc_auth.get_plugin_class(self.auth_type)
except Exception as e:
@ -2363,8 +2363,6 @@ class OperatorCloud(OpenStackCloud):
@property
def ironic_client(self):
if self._ironic_client is None:
ironic_logging = logging.getLogger('ironicclient')
ironic_logging.addHandler(logging.NullHandler())
token = self.auth_token
if self.auth_type in (None, "None", ''):
# TODO: This needs to be improved logic wise, perhaps a list,