fixed timestamps not matching the transaction when saving to log file

This commit is contained in:
Alexander 2024-08-24 16:30:20 -04:00
parent ac603bed07
commit 490d21acbd
2 changed files with 3 additions and 3 deletions

View file

@ -20,7 +20,7 @@ def set_channel_logger(channel_name, level=logging.INFO):
os.makedirs("{}/logs/".format(os.getenv("DATA_FOLDER")), exist_ok=True)
log_file = "{}/logs/{}.log".format(os.getenv("DATA_FOLDER"), channel_name)
handler = TimedRotatingFileHandler(log_file, when="midnight", interval=1, utc=True)
handler.setFormatter(logging.Formatter("[%(asctime)s] %(message)s", "%Y-%m-%d %H:%M:%S"))
handler.setFormatter(logging.Formatter("%(message)s"))
logger = logging.getLogger(channel_name)
logger.setLevel(level)
logger.addHandler(handler)

View file

@ -78,9 +78,9 @@ def output_line(event):
raise Exception("Could not get block {}".format(block_number))
# log the message and output to console
message = "{}:{} {}".format(decoded_data[0]['args']['Soul'], decoded_data[0]['args']['Aura'], decoded_data[0]['args']['LogLine'])
log_message(os.getenv('CHANNEL_NAME'), message)
timestamp = datetime.fromtimestamp(block_cache[block_number]['timestamp'], tz=timezone.utc)
message = "{}:{} {}".format(decoded_data[0]['args']['Soul'], decoded_data[0]['args']['Aura'], decoded_data[0]['args']['LogLine'])
log_message(os.getenv('CHANNEL_NAME'), "[{}] {}".format(timestamp.strftime("%Y-%m-%d %H:%M:%S"), message))
print("[{}] {}".format(timestamp.strftime("%Y-%m-%d %H:%M:%S"), message if os.getenv('SHOW_AURA_AND_SOUL') != '0' else decoded_data[0]['args']['LogLine']))
# save latest block number