From fbca1644823acbe4165ad1087db5baed28a6809d Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Sat, 26 Nov 2016 18:12:36 -0300 Subject: [refactor] improve logging Some exceptions were missing a proper description and client_side_db.py script wasn't capturing logs from Twisted. --- client/src/leap/soledad/client/http_target/fetch.py | 2 +- client/src/leap/soledad/client/http_target/fetch_protocol.py | 2 +- scripts/db_access/client_side_db.py | 9 +++++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/client/src/leap/soledad/client/http_target/fetch.py b/client/src/leap/soledad/client/http_target/fetch.py index 85e2967d..df07a96a 100644 --- a/client/src/leap/soledad/client/http_target/fetch.py +++ b/client/src/leap/soledad/client/http_target/fetch.py @@ -149,7 +149,7 @@ class HTTPDocFetcher(object): return (metadata['number_of_changes'], metadata['new_generation'], metadata['new_transaction_id']) except (ValueError, KeyError): - raise errors.BrokenSyncStream + raise errors.BrokenSyncStream('Metadata parsing failed') def _emit_receive_status(user_data, received_docs, total): diff --git a/client/src/leap/soledad/client/http_target/fetch_protocol.py b/client/src/leap/soledad/client/http_target/fetch_protocol.py index 3322ec70..fa6b1969 100644 --- a/client/src/leap/soledad/client/http_target/fetch_protocol.py +++ b/client/src/leap/soledad/client/http_target/fetch_protocol.py @@ -136,7 +136,7 @@ class DocStreamReceiver(ReadBodyProtocol): Checks that ']' came and stream was properly closed. """ if not self._properly_finished: - raise errors.BrokenSyncStream() + raise errors.BrokenSyncStream('Stream not properly closed') content = self._buffer.getvalue()[0:self._buffer.tell()] self._buffer.close() return content diff --git a/scripts/db_access/client_side_db.py b/scripts/db_access/client_side_db.py index 2acee2b5..48eec0f7 100644 --- a/scripts/db_access/client_side_db.py +++ b/scripts/db_access/client_side_db.py @@ -1,13 +1,13 @@ #!/usr/bin/python import os +import sys import argparse import tempfile import getpass import requests import srp._pysrp as srp import binascii -import logging import json import time @@ -15,6 +15,7 @@ from twisted.internet import reactor from twisted.internet.defer import inlineCallbacks from leap.soledad.client import Soledad +from leap.soledad.common.log import getLogger from leap.keymanager import KeyManager from leap.keymanager.openpgp import OpenPGPKey @@ -39,9 +40,9 @@ Use the --help option to see available options. # create a logger -logger = logging.getLogger(__name__) -LOG_FORMAT = '%(asctime)s %(message)s' -logging.basicConfig(format=LOG_FORMAT, level=logging.DEBUG) +logger = getLogger(__name__) +from twisted.python import log +log.startLogging(sys.stdout) safe_unhexlify = lambda x: binascii.unhexlify(x) if ( -- cgit v1.2.3