Adjustments to PR

This commit is contained in:
Twentysix 2016-04-16 22:31:18 +02:00
parent 4fb5ba75b4
commit a351f2fc2a

12
red.py
View File

@ -431,6 +431,12 @@ def set_logger():
handler.setFormatter(logging.Formatter('%(asctime)s %(message)s', datefmt="[%d/%m/%Y %H:%M]")) handler.setFormatter(logging.Formatter('%(asctime)s %(message)s', datefmt="[%d/%m/%Y %H:%M]"))
logger.addHandler(handler) logger.addHandler(handler)
logger = logging.getLogger("red")
logger.setLevel(logging.WARNING)
handler = logging.FileHandler(filename='data/red/red.log', encoding='utf-8', mode='a')
handler.setFormatter(logging.Formatter('%(asctime)s %(message)s', datefmt="[%d/%m/%Y %H:%M]"))
logger.addHandler(handler)
def get_answer(): def get_answer():
choices = ("yes", "y", "no", "n") choices = ("yes", "y", "no", "n")
c = "" c = ""
@ -530,12 +536,12 @@ if __name__ == '__main__':
try: try:
loop.run_until_complete(main()) loop.run_until_complete(main())
except discord.LoginFailure: except discord.LoginFailure:
traceback.print_exc() logger.error(traceback.format_exc())
print("Invalid login credentials. Restart Red and configure it properly.") print("Invalid login credentials. Restart Red and configure it properly.")
shutil.copy('data/red/settings.json', 'data/red/settings.json-{}'.format(int(time.time()))) shutil.copy('data/red/settings.json', 'data/red/settings-{}.bak'.format(int(time.time())))
os.remove('data/red/settings.json') # Hopefully this won't backfire in case of discord servers' problems os.remove('data/red/settings.json') # Hopefully this won't backfire in case of discord servers' problems
except: except:
traceback.print_exc() logger.error(traceback.format_exc())
loop.run_until_complete(bot.logout()) loop.run_until_complete(bot.logout())
finally: finally:
loop.close() loop.close()