Figured it out, hope this helps anyone in the future who may have the same issues.
def logger():
logging.basicConfig(level=logging.INFO, filename="bandit.log", filemode="w", format="%(asctime)s - %(levelname)s - %(message)s")
logger = logging.getLogger(__name__)
logger.propagate = False
handler = logging.FileHandler('anomaly.log')
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
handler.setFormatter(formatter)
logger.addHandler(handler)
try:
location = pyautogui.locateOnScreen('1.png', confidence=0.9)
if pyautogui.locateOnScreen('1.png', confidence=0.9):
global call_count
call_count += 1
logger.info(call_count)
except pyautogui.ImageNotFoundException:
pass