summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Heimes <christian@python.org>2015-11-11 15:25:50 +0100
committerSimo Sorce <simo@redhat.com>2015-11-11 11:35:45 -0500
commitd944441d2a6d0c8619e61ba7ceff16d6b147a76b (patch)
tree23f598254b17ca39e70bc252f77f0f2a86e2d534
parent3b7eed15c3f9da7381d240a762b0e557dd18ce96 (diff)
downloadcustodia-d944441d2a6d0c8619e61ba7ceff16d6b147a76b.tar.gz
custodia-d944441d2a6d0c8619e61ba7ceff16d6b147a76b.tar.xz
custodia-d944441d2a6d0c8619e61ba7ceff16d6b147a76b.zip
Custodia client loggingreview
custodia.client library now logs requests and responses. The auditfile argument of setup_logging() can be set to None to configure client logging without audit file. Signed-off-by: Christian Heimes <cheimes@redhat.com> Reviewed-by: Simo Sorce <simo@redhat.com>
-rw-r--r--Makefile6
-rw-r--r--custodia/client.py5
-rw-r--r--custodia/log.py2
3 files changed, 10 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index dc5291f..caf7f31 100644
--- a/Makefile
+++ b/Makefile
@@ -12,8 +12,10 @@ lint:
./custodia
clean:
- rm -fr build dist *.egg-info
- find ./ -name '*.pyc' -exec rm -f {} \;
+ rm -fr build dist *.egg-info .tox
+ rm -f server_socket
+ find ./ -name '*.py[co]' -exec rm -f {} \;
+ find ./ -name __pycache__ -exec rm -rf {} \;
cscope:
git ls-files | xargs pycscope
diff --git a/custodia/client.py b/custodia/client.py
index 9647d68..dad1142 100644
--- a/custodia/client.py
+++ b/custodia/client.py
@@ -1,5 +1,6 @@
# Copyright (C) 2015 Custodia Project Contributors - see LICENSE file
+import logging
import socket
from jwcrypto.common import json_decode
@@ -17,6 +18,8 @@ from custodia.message.kem import (
check_kem_claims, decode_enc_kem, make_enc_kem
)
+logger = logging.getLogger(__name__)
+
class HTTPUnixConnection(HTTPConnection):
@@ -79,7 +82,9 @@ class CustodiaHTTPClient(object):
self._last_response = None
url = self._join_url(path)
kwargs['headers'] = self._add_headers(**kwargs)
+ logger.debug("%s %s", cmd.__name__.upper(), url)
self._last_response = cmd(url, **kwargs)
+ logger.debug("Response: %s", self._last_response)
return self._last_response
@property
diff --git a/custodia/log.py b/custodia/log.py
index 313a7fc..e175cdb 100644
--- a/custodia/log.py
+++ b/custodia/log.py
@@ -45,7 +45,7 @@ def setup_logging(debug=False, auditfile='custodia.audit.log'):
custodia_logger.setLevel(logging.INFO)
audit_logger = logging.getLogger('custodia.audit')
- if len(audit_logger.handlers) == 0:
+ if auditfile is not None and len(audit_logger.handlers) == 0:
audit_fmt = logging.Formatter(LOGGING_FORMAT, LOGGING_DATEFORMAT)
audit_hdrl = logging.FileHandler(auditfile)
audit_hdrl.setFormatter(audit_fmt)