From 9f95446a55533c8cdceec7c4430be5cad752ecb1 Mon Sep 17 00:00:00 2001 From: "Kali Kaneko (leap communications)" Date: Tue, 25 Apr 2017 18:00:12 +0200 Subject: [bug] unify logging style using class attr I changed most of the logger statements to use a class attribute, in this way it's easier to identify which class it's logging them. in some cases I leave a module-level logger, when we're either using functions or when the module it's too small. at the same time I did a general review and cleanup of the logging statements. --- src/leap/bitmask/bonafide/session.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/leap/bitmask/bonafide/session.py') diff --git a/src/leap/bitmask/bonafide/session.py b/src/leap/bitmask/bonafide/session.py index 732afe53..551bfa2e 100644 --- a/src/leap/bitmask/bonafide/session.py +++ b/src/leap/bitmask/bonafide/session.py @@ -24,7 +24,6 @@ from leap.bitmask.bonafide import _srp from leap.bitmask.bonafide import provider from leap.bitmask.bonafide._http import httpRequest, cookieAgentFactory -logger = Logger() OK = 'ok' @@ -45,6 +44,8 @@ def _auth_required(func): class Session(object): + log = Logger() + def __init__(self, credentials, api, provider_cert): # TODO check if an anonymous credentials is passed. # TODO move provider_cert to api object. @@ -91,7 +92,7 @@ class Session(object): def authenticate(self): uri = self._api.get_handshake_uri() met = self._api.get_handshake_method() - logger.debug("%s to %s" % (met, uri)) + self.log.debug('%s to %s' % (met, uri)) params = self._srp_auth.get_handshake_params() handshake = yield self._request(self._agent, uri, values=params, @@ -101,7 +102,7 @@ class Session(object): uri = self._api.get_authenticate_uri(login=self.username) met = self._api.get_authenticate_method() - logger.debug("%s to %s" % (met, uri)) + self.log.debug('%s to %s' % (met, uri)) params = self._srp_auth.get_authentication_params() auth = yield self._request(self._agent, uri, values=params, @@ -119,9 +120,7 @@ class Session(object): def logout(self): uri = self._api.get_logout_uri() met = self._api.get_logout_method() - auth = yield self._request(self._agent, uri, method=met) - print 'AUTH', auth - print 'resetting user/pass' + yield self._request(self._agent, uri, method=met) self.username = None self.password = None self._initialize_session() @@ -211,6 +210,8 @@ if __name__ == "__main__": import sys from twisted.cred.credentials import UsernamePassword + log = Logger() + if len(sys.argv) != 4: print "Usage:", sys.argv[0], "provider", "username", "password" sys.exit() @@ -229,7 +230,7 @@ if __name__ == "__main__": reactor.stop() def auth_eb(failure): - logger.error(failure) + log.error(failure) d = session.authenticate() d.addCallback(print_result) -- cgit v1.2.3