Ver Fonte

Cleaned up logging

allens há 1 dia atrás
pai
commit
0bc14d75cd
1 ficheiros alterados com 7 adições e 12 exclusões
  1. 7 12
      nagbot.py

+ 7 - 12
nagbot.py

@@ -6,12 +6,7 @@ import config
 import logging
 import requests
 
-logging.basicConfig(filename=config.logfile, level=logging.INFO)
-
-
-def get_now():  # Create a timestamp for logging
-    now = str(time.strftime("%Y/%m/%d %H:%M:%S"))
-    return now
+logging.basicConfig(filename=config.logfile, level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
 
 
 def live_now():  # Check if the stream is live
@@ -21,18 +16,18 @@ def live_now():  # Check if the stream is live
 
 
 def send_msg(msg):
-    if live_now() is True:
-        logging.info(f'{get_now()} - Sending \"{msg}\"...')
+    if live_now():
+        logging.info(f'Sending \"{msg}\"...')
         new_status = {'body': msg}
         headers = {'Authorization': f'Bearer {config.auth_bearer}'}
         response = requests.post(f'{config.owncast_url}/api/integrations/chat/send', data=json.dumps(new_status), headers=headers)
         return response.json()
     else:
-        logging.info(f'{get_now()} - Owncast stream is not live, so not sending messages.')
+        logging.info(f'Owncast stream is not live, so not sending messages.')
 
 
 def main():
-    logging.info(f'{get_now()} - Starting nagbot...')
+    logging.info(f'Starting nagbot...')
     for nag in config.nags:
         send_msg(nag)
         time.sleep(config.interval)  # Wait between messages
@@ -42,9 +37,9 @@ try:
     while True:
         main()
 except KeyboardInterrupt:
-    logging.info(f'{get_now()} - Ctrl-alt-delete caught. Exiting program...')
+    logging.info(f'Ctrl-alt-delete caught. Exiting program...')
     print('Ctrl-alt-delete caught. Exiting program...')
     sys.exit()
 except Exception as error:
-    logging.info(f'{get_now()} - \n{error}\n')
+    logging.info(f'\n{error}\n')
     sys.exit()