diff --git a/app/app.py b/app/app.py index 72d74c9..b303839 100644 --- a/app/app.py +++ b/app/app.py @@ -1,24 +1,13 @@ -from app.factory import create_app +import logging from logging.config import dictConfig +from app.factory import create_app -dictConfig({ - 'version': 1, - 'formatters': {'default': { - 'format': '[%(asctime)s] %(levelname)s in %(module)s: %(message)s', - }}, - 'handlers': {'wsgi': { - 'class': 'logging.StreamHandler', - 'stream': 'ext://flask.logging.wsgi_errors_stream', - 'formatter': 'default' - }}, - 'root': { - 'level': 'INFO', - 'handlers': ['wsgi'] - } -}) - app = create_app() + if __name__ == '__main__': app.run() + gunicorn_logger = logging.getLogger('gunicorn.error') + app.logger.handlers = gunicorn_logger.handlers + app.logger.setLevel(gunicorn_logger.level) diff --git a/app/library/cache.py b/app/library/cache.py index e417649..ea130af 100644 --- a/app/library/cache.py +++ b/app/library/cache.py @@ -15,7 +15,7 @@ class Cache(object): self.redis = Redis(host=config.CACHE_HOST, port=config.CACHE_PORT) def store_data(self, item_name, expiration_minutes, data): - current_app.logger.info(f'MISS - {item_name} - {expiration_minutes} minutes') + current_app.logger.info(f'SET - {item_name} - expires in {expiration_minutes} minutes') self.redis.setex( item_name, timedelta(minutes=expiration_minutes), @@ -29,6 +29,7 @@ class Cache(object): current_app.logger.info(f'HIT - {key_name}') return json_loads(data) else: + current_app.logger.info(f'MISS - {key_name}') try: dns = f'{codename}.node.{config.DO_DOMAIN}' url = f'http://{dns}:18081/get_info' @@ -46,8 +47,9 @@ class Cache(object): current_app.logger.info(f'HIT - {key_name}') return json_loads(data) else: + current_app.logger.info(f'MISS - {key_name}') txes = wallet.get_transfers(account_idx) - self.store_data(key_name, 1, json_dumps(txes)) + self.store_data(key_name, 2, json_dumps(txes)) return txes def get_balances(self, account_idx, atomic=True): @@ -61,6 +63,7 @@ class Cache(object): current_app.logger.info(f'HIT - {key_name}') return json_loads(data) else: + current_app.logger.info(f'MISS - {key_name}') balances = wallet.balances(account_idx, atomic) data = {'balance': balances[0], 'unlocked': balances[1]} self.store_data(key_name, 2, json_dumps(data)) @@ -75,6 +78,7 @@ class Cache(object): current_app.logger.info(f'HIT - {key_name}') return json_loads(data) else: + current_app.logger.info(f'MISS - {key_name}') droplet = do.show_droplet(droplet_id) self.store_data(key_name, 120, json_dumps(droplet)) return droplet @@ -86,6 +90,7 @@ class Cache(object): current_app.logger.info(f'HIT - {key_name}') return json_loads(data) else: + current_app.logger.info(f'MISS - {key_name}') volume = do.show_volume(volume_id) self.store_data(key_name, 120, json_dumps(volume)) return volume @@ -97,6 +102,7 @@ class Cache(object): current_app.logger.info(f'HIT - {key_name}') return float(data.decode()) else: + current_app.logger.info(f'MISS - {key_name}') d = get_market_data() amt = d['market_data']['current_price'][cur] self.store_data(key_name, 5, amt) @@ -109,6 +115,7 @@ class Cache(object): current_app.logger.info(f'HIT - {key_name}') return json_loads(data) else: + current_app.logger.info(f'MISS - {key_name}') wallet.get_transfers(subaddress_index) self.store_data(key_name, 2, json_dumps(data)) return data diff --git a/app/library/coingecko.py b/app/library/coingecko.py index f3bd15e..80dbeb4 100644 --- a/app/library/coingecko.py +++ b/app/library/coingecko.py @@ -13,6 +13,6 @@ def get_market_data(coin_name='monero'): } headers = {'accept': 'application/json'} url = f'https://api.coingecko.com/api/v3/coins/{coin_name}' - current_app.logger.info(f'Fetching {coin_name} price metrics from CoinGecko') + current_app.logger.info(f'GET - {url}') r = r_get(url, headers=headers, data=data) return r.json()