Merge branch 'master' into 'main'
change startup and logging See merge request crate/garfbot!2
This commit is contained in:
commit
a2da5d3ea6
32
garfbot.py
32
garfbot.py
@ -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())
|
||||||
|
Loading…
Reference in New Issue
Block a user