summaryrefslogtreecommitdiff
path: root/src/leap/bitmask/keymanager/nicknym.py
diff options
context:
space:
mode:
authorKali Kaneko (leap communications) <kali@leap.se>2017-04-25 18:00:12 +0200
committerKali Kaneko (leap communications) <kali@leap.se>2017-04-27 19:33:28 +0200
commit9f95446a55533c8cdceec7c4430be5cad752ecb1 (patch)
tree4265c127ee9b2c5f1e038836ad2e7b92ea0cad80 /src/leap/bitmask/keymanager/nicknym.py
parent9a1548aa01996ce93febe0272f1f8e4dd5e130ff (diff)
[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.
Diffstat (limited to 'src/leap/bitmask/keymanager/nicknym.py')
-rw-r--r--src/leap/bitmask/keymanager/nicknym.py26
1 files changed, 12 insertions, 14 deletions
diff --git a/src/leap/bitmask/keymanager/nicknym.py b/src/leap/bitmask/keymanager/nicknym.py
index 7c738da..8e3a08f 100644
--- a/src/leap/bitmask/keymanager/nicknym.py
+++ b/src/leap/bitmask/keymanager/nicknym.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# nicknym.py
-# Copyright (C) 2016 LEAP
+# Copyright (C) 2016-2017 LEAP
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -17,10 +17,10 @@
import json
import sys
-import logging
import urllib
from twisted.internet import defer
+from twisted.logger import Logger
from twisted.web import client
from twisted.web._responses import NOT_FOUND
@@ -30,14 +30,14 @@ from leap.common.http import HTTPClient
from leap.common.decorators import memoized_method
-logger = logging.getLogger(__name__)
-
-
class Nicknym(object):
+
"""
Responsible for communication to the nicknym server.
"""
+ log = Logger()
+
PUBKEY_KEY = "user[public_key]"
def __init__(self, nickserver_uri, ca_cert_path, token):
@@ -83,12 +83,12 @@ class Nicknym(object):
body=str(data),
headers=headers)
except Exception as e:
- logger.warning("Error uploading key: %r" % (e,))
+ self.log.warn('Error uploading key: %r' % (e,))
raise e
if 'error' in res:
# FIXME: That's a workaround for 500,
# we need to implement a readBody to assert response code
- logger.warning("Error uploading key: %r" % (res,))
+ self.log.warn('Error uploading key: %r' % (res,))
raise Exception(res)
@defer.inlineCallbacks
@@ -105,19 +105,17 @@ class Nicknym(object):
try:
content = yield self._fetch_and_handle_404_from_nicknym(uri)
json_content = json.loads(content)
-
except KeyNotFound:
raise
except IOError as e:
- logger.warning("HTTP error retrieving key: %r" % (e,))
- logger.warning("%s" % (content,))
+ self.log.warn('HTTP error retrieving key: %r' % (e,))
+ self.log.warn("%s" % (content,))
raise KeyNotFound(e.message), None, sys.exc_info()[2]
except ValueError as v:
- logger.warning("Invalid JSON data from key: %s" % (uri,))
+ self.log.warn('Invalid JSON data from key: %s' % (uri,))
raise KeyNotFound(v.message + ' - ' + uri), None, sys.exc_info()[2]
-
except Exception as e:
- logger.warning("Error retrieving key: %r" % (e,))
+ self.log.warn('Error retrieving key: %r' % (e,))
raise KeyNotFound(e.message), None, sys.exc_info()[2]
# Responses are now text/plain, although it's json anyway, but
# this will fail when it shouldn't
@@ -141,7 +139,7 @@ class Nicknym(object):
if response.code == NOT_FOUND:
message = ' %s: Key not found. Request: %s' \
% (response.code, uri)
- logger.warning(message)
+ self.log.warn(message)
raise KeyNotFound(message), None, sys.exc_info()[2]
return response