Commit 85115c12 authored by Stavros Sachtouris's avatar Stavros Sachtouris

Log astakosclient in kamaki style

parent a2ed4352
......@@ -67,6 +67,7 @@ def with_temp_token(foo):
class _init_synnefo_astakosclient(_command_init):
@errors.generic.all
@errors.user.load
@errors.user.astakosclient
......
......@@ -145,7 +145,7 @@ class RequestManager(Logged):
self.scheme, self.netloc = self._connection_info(url, path, params)
def dump_log(self):
plog = '\t[%s]' if self.LOG_PID else ''
plog = ('\t[%s]' % self) if self.LOG_PID else ''
sendlog.info('- - - - - - -')
sendlog.info('%s %s://%s%s%s' % (
self.method, self.scheme, self.netloc, self.path, plog))
......@@ -182,7 +182,7 @@ class RequestManager(Logged):
wait = 0.03 * random()
sleep(wait)
keep_trying -= wait
plog = '\t[%s]' if self.LOG_PID else ''
plog = ('\t[%s]' % self) if self.LOG_PID else ''
logmsg = 'Kamaki Timeout %s %s%s' % (self.method, self.path, plog)
recvlog.debug(logmsg)
raise ClientError('HTTPResponse takes too long - kamaki timeout')
......@@ -244,8 +244,8 @@ class ResponseManager(Logged):
data = '%s%s' % (self._content, plog)
if self._token:
data = data.replace(self._token, '...')
sendlog.info(data)
sendlog.info('- - - - - - -')
recvlog.info(data)
recvlog.info('- - - - - - -')
break
except Exception as err:
if isinstance(err, HTTPException):
......@@ -450,7 +450,7 @@ class Client(Logged):
if data:
headers.setdefault('Content-Length', '%s' % len(data))
plog = '\t[%s]' if self.LOG_PID else ''
plog = ('\t[%s]' % self) if self.LOG_PID else ''
sendlog.debug('\n\nCMT %s@%s%s', method, self.base_url, plog)
req = RequestManager(
method, self.base_url, path,
......
......@@ -32,10 +32,11 @@
# or implied, of GRNET S.A.
from logging import getLogger
from astakosclient import AstakosClient as SynnefoAstakosClient
from astakosclient import AstakosClient as SynnefoAstakosClientOrig
from astakosclient import AstakosClientException as SynnefoAstakosClientError
from kamaki.clients import Client, ClientError
from kamaki.clients import (
Client, ClientError, Logged, RequestManager, recvlog)
def _astakos_error(foo):
......@@ -47,6 +48,50 @@ def _astakos_error(foo):
return wrap
class SynnefoAstakosClient(SynnefoAstakosClientOrig, Logged):
"""A synnefo astakosclient.AstakosClient wrapper, that logs"""
def _dump_response(self, request, status, message, data):
plog = ''
if self.LOG_PID:
recvlog.info('\n%s <-- [req: %s]\n' % (self, request))
plog = '\t[%s]' % self
recvlog.info('%d %s%s' % (status, message, plog))
recvlog.info('data size: %s%s' % (len(data), plog))
if self.LOG_DATA and data:
data = '%s%s' % (data, plog)
if not self.LOG_TOKEN:
token = request.headers.get('X-Auth-Token', '')
if token:
data = data.replace(token, '...')
recvlog.info(data)
recvlog.info('- - - - - - -')
def _call_astakos(self, *args, **kwargs):
r = super(SynnefoAstakosClient, self)._call_astakos(*args, **kwargs)
try:
log_request = getattr(self, 'log_request', None)
if log_request:
req = RequestManager(
method=log_request['method'],
url='%s://%s' % (self.scheme, self.astakos_base_url),
path=log_request['path'],
data=log_request.get('body', None),
headers=log_request.get('headers', dict()))
req.dump_log()
log_response = getattr(self, 'log_response', None)
if log_response:
self._dump_response(
req,
status=log_response['status'],
message=log_response['message'],
data=log_response.get('data', ''))
except Exception as e:
print 'GOT EXCEPTION', e
finally:
return r
class AstakosClient(Client):
"""Synnefo Astakos cached client wraper"""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment