change startup and logging

This commit is contained in:
crate 2024-10-01 21:19:33 -05:00
parent 9faafe70a6
commit 0c450d9fa2

View File

@ -18,22 +18,25 @@ from operator import itemgetter
from logging.handlers import TimedRotatingFileHandler from logging.handlers import TimedRotatingFileHandler
# Log Setup # Log setup
logger = logging.getLogger('garflog') logger = logging.getLogger('garflog')
logger.setLevel(logging.INFO) logger.setLevel(logging.INFO)
handler = TimedRotatingFileHandler( file_handler = TimedRotatingFileHandler(
'garfbot.log', 'garfbot.log',
when='midnight', when='midnight',
interval=1, interval=1,
backupCount=7, backupCount=7,
delay=True # Flush output immediately delay=True # Counterintuitively, will flush output immediately
) )
console_handler = logging.StreamHandler()
formatter=logging.Formatter( formatter=logging.Formatter(
'%(asctime)s [%(levelname)s] %(message)s', '%(asctime)s [%(levelname)s] %(message)s',
datefmt='%Y-%m-%d %H:%M:%S' datefmt='%Y-%m-%d %H:%M:%S'
) )
handler.setFormatter(formatter) file_handler.setFormatter(formatter)
logger.addHandler(handler) console_handler.setFormatter(formatter)
logger.addHandler(file_handler)
logger.addHandler(console_handler)
# Bot Setup # Bot Setup
@ -415,9 +418,16 @@ async def on_error(event, *args, **kwargs):
# Run GarfBot! # Run GarfBot!
try: async def garfbot_connect()
garfbot.run(garfkey) while True:
except Exception as e: try:
e = str(e) garfbot.start(garfkey)
logger.error(f"GarfBot Init Error: {e}") except Exception as e:
print(f"GarfBot Init Error: {e}", flush=True) e = str(e)
logger.error(f"Garfbot couldn't connect! {e}")
print(f"Garfbot couldn't connect! {e}", flush=True)
await asyncio.sleep(300)
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(garfbot_connect())