diff --git a/bit/logger.py b/bit/logger.py new file mode 100644 index 0000000..9b85dc8 --- /dev/null +++ b/bit/logger.py @@ -0,0 +1,5 @@ +import logging + +logger = logging.getLogger("Bit") +handler = logging.StreamHandler() +handler.setFormatter(logging.Formatter("%(asctime)s|%(levelname)s|%(name)s|%(message)s")) diff --git a/bit/network/fees.py b/bit/network/fees.py index 1205894..1d70fc9 100644 --- a/bit/network/fees.py +++ b/bit/network/fees.py @@ -1,4 +1,4 @@ -import logging +from bit.logger import logger from functools import wraps from time import time @@ -57,12 +57,12 @@ def wrapper(fast=True): fast_last_update = now except (ConnectionError, HTTPError, Timeout): # pragma: no cover if cached_fee_fast is None: - logging.warning( + logger.warning( 'Connection to fee API failed, returning default fee (fast) of {}'.format(DEFAULT_FEE_FAST) ) return DEFAULT_FEE_FAST else: - logging.warning('Connection to fee API failed, returning cached fee (fast).') + logger.warning('Connection to fee API failed, returning cached fee (fast).') return cached_fee_fast return cached_fee_fast @@ -81,12 +81,12 @@ def wrapper(fast=True): hour_last_update = now except (ConnectionError, HTTPError, Timeout): # pragma: no cover if cached_fee_hour is None: - logging.warning( + logger.warning( 'Connection to fee API failed, returning default fee (hour) of {}'.format(DEFAULT_FEE_HOUR) ) return DEFAULT_FEE_HOUR else: - logging.warning('Connection to fee API failed, returning cached fee (hour).') + logger.warning('Connection to fee API failed, returning cached fee (hour).') return cached_fee_hour return cached_fee_hour diff --git a/bit/network/services.py b/bit/network/services.py index 9578c63..21defdf 100644 --- a/bit/network/services.py +++ b/bit/network/services.py @@ -1,6 +1,6 @@ import requests import json -import logging +from bit.logger import logger from decimal import Decimal, getcontext from bit.constants import BTC @@ -73,7 +73,7 @@ def broadcast_tx(self, tx_hex): try: _ = self.sendrawtransaction(tx_hex) except BitcoinNodeException as e: - logging.warning(e) + logger.warning(e) return False return True diff --git a/bit/transaction.py b/bit/transaction.py index cfdc1c2..99c723a 100644 --- a/bit/transaction.py +++ b/bit/transaction.py @@ -1,4 +1,4 @@ -import logging +from bit.logger import logger from collections import namedtuple from itertools import islice import math @@ -194,7 +194,7 @@ def estimate_tx_fee(in_size, n_in, out_size, n_out, satoshis, segwit=False): estimated_fee = estimated_size * satoshis - logging.debug('Estimated fee: {} satoshis for {} bytes'.format(estimated_fee, estimated_size)) + logger.debug('Estimated fee: {} satoshis for {} bytes'.format(estimated_fee, estimated_size)) return estimated_fee