better logging

This commit is contained in:
Dobromir Popov 2024-10-21 11:37:24 +03:00
parent fdd3a66644
commit d71927ddc4

View File

@ -67,6 +67,7 @@ os.makedirs(log_dir, exist_ok=True)
error_file_handler = RotatingFileHandler( log_file, maxBytes=10*1024*1024, backupCount=5)
error_file_handler.setLevel(logging.ERROR)
error_file_handler.setFormatter(logging.Formatter('%(asctime)s [%(levelname)s] %(message)s', datefmt='%Y-%m-%d %H:%M:%S') )
error_file_handler.formatter.converter = time.localtime
error_logger = logging.getLogger('error_logger')
error_logger.setLevel(logging.ERROR)
error_logger.addHandler(error_file_handler)
@ -945,19 +946,20 @@ async def save_token_info():
with open('./logs/token_info.json', 'w') as f:
json.dump(TOKENS_INFO, f, indent=2)
async def get_transaction_details_with_retry(transaction_id, retry_delay = 8, max_retries = 16):
async def get_transaction_details_with_retry(transaction_id, retry_delay = 5, max_retries = 16):
# wait for the transaction to be confirmed
# await async_client.wait_for_confirmation(Signature.from_string(transaction_id))
# qwery every 5 seconds for the transaction details untill not None or 30 seconds
# query every 5 seconds for the transaction details until not None or 30 seconds
for _ in range(max_retries):
try:
tx_details = await get_transaction_details_rpc(transaction_id)
if tx_details is not None:
break
except Exception as e:
logging.error(f"Error fetching transaction details: {e}")
logging.error(f"Error fetching transaction details for '{transaction_id}': {e}")
logging.info(f"({_} of {max_retries}) Waiting for transaction details for {transaction_id}")
await asyncio.sleep(retry_delay)
retry_delay *= 1.2
return tx_details
@ -1084,6 +1086,7 @@ async def process_log(log_result):
except Exception as e:
logging.error(f"Error aquiring log details and following: {e}")
error_logger.info(f"Error aquiring log details and following:\n {tr_details}")
await send_telegram_message(f"Not followed! Error following move.")
except Exception as e: