Less debug and info messages to log

This commit is contained in:
Scott Idem
2024-10-08 13:47:43 -04:00
parent 39a1c05df1
commit e6e7275de0
2 changed files with 14 additions and 7 deletions

View File

@@ -1,4 +1,4 @@
import datetime, json, pytz, redis, secrets
import datetime, json, pytz, random, redis, secrets
from timeit import default_timer as timer
from app.config import settings
@@ -703,8 +703,8 @@ def sql_select(
)
elif table_name and field_name and field_value and not (record_id or record_id_random or sql or data):
# Select all records from a table with a specific field and field value
# Updated 2023-11-30
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
# Updated 2024-10-08
# log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.info('Select all records from a table with a specific field and field value')
if not data:
@@ -1251,7 +1251,8 @@ def redis_lookup_id_random(
table_name: str,
check_int_id: bool = False,
log_lvl: int = logging.INFO, # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
minutes: int = 1,
minutes: int = 8, # Expire the Redis key after 8 minutes
reset_rate: int = 10, # 1 in 10 chance of resetting the Redis key
) -> str|int|bool|None:
log.setLevel(log_lvl)
@@ -1270,7 +1271,7 @@ def redis_lookup_id_random(
log.info(f'The int ID does not exists. Returning False. Table Name: {table_name} ID: {record_id}')
return False
else:
log.info(f'Not checking if the int ID exists. Returning the int ID. ID: {record_id}')
log.debug(f'Not checking if the int ID exists. Returning the int ID. ID: {record_id}')
return record_id
elif record_id_random is None:
log.info(f'No record ID was passed. Returning None')
@@ -1317,6 +1318,11 @@ def redis_lookup_id_random(
# WARNING WARNING WARNING
# WARNING WARNING WARNING
# To help prevent corrupt data from being stored in Redis for too long, we will set the record_id to None 25% of the time. This will force the function to look up the record_id in the database. This is a temporary solution. Why is the data from SQL not correct in the first place??? -2024-10-08
if record_id and random.randint(1, reset_rate) == 1:
log.warning(f'Redis: Randomly (1/{reset_rate}) setting record_id to None. Key="{key_name}" value="{record_id}" TTL={r.ttl(key_name)} seconds')
record_id = None
if record_id:
r.setex(key_name, datetime.timedelta(minutes=1), value=record_id)
log.info(f'Redis: Entry found for: Key="{key_name}" value="{record_id}" TTL={r.ttl(key_name)} seconds')