Merge pull request #446 from tipabu/improved-errors-and-logging

Improve errors and logging
This commit is contained in:
Peter Hamilton 2018-06-28 11:23:11 -04:00 committed by GitHub
commit a931850c51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 6 deletions

View File

@ -93,7 +93,7 @@ class ProxyKmipClient(object):
Optional, defaults to None.
"""
self.logger = logging.getLogger()
self.logger = logging.getLogger(__name__)
self.attribute_factory = attributes.AttributeFactory()
self.object_factory = factory.ObjectFactory()
@ -131,7 +131,7 @@ class ProxyKmipClient(object):
self.proxy.open()
self._is_open = True
except Exception as e:
self.logger.exception("could not open client connection", e)
self.logger.error("could not open client connection: %s", e)
raise
def close(self):
@ -148,7 +148,7 @@ class ProxyKmipClient(object):
self.proxy.close()
self._is_open = False
except Exception as e:
self.logger.exception("could not close client connection", e)
self.logger.error("could not close client connection: %s", e)
raise
@is_connected

View File

@ -62,6 +62,7 @@ import os
import six
import socket
import ssl
import sys
FILE_PATH = os.path.dirname(os.path.abspath(__file__))
CONFIG_FILE = os.path.normpath(os.path.join(FILE_PATH, '../kmipconfig.ini'))
@ -224,15 +225,15 @@ class KMIPProxy:
self.socket.connect((self.host, self.port))
except Exception as e:
self.logger.error("An error occurred while connecting to "
"appliance " + self.host)
"appliance %s: %s", self.host, e)
self.socket.close()
last_error = e
last_error = sys.exc_info()
else:
return
self.socket = None
if last_error:
raise last_error
six.reraise(*last_error)
def _create_socket(self, sock):
self.socket = ssl.wrap_socket(