diff --git a/bot.py b/bot.py index 1f75c38..7437507 100644 --- a/bot.py +++ b/bot.py @@ -1,4 +1,6 @@ import discord +import logging +from datetime import datetime from utilities import getConfig from discord.ext import commands @@ -13,6 +15,14 @@ def __init__(self): # get config self.config = getConfig() + #setup logger if logging is true + if(self.config['bot']['logging'].lower() == 'true'): + logger = logging.getLogger('discord') + logger.setLevel((logging.DEBUG if self.config['bot']['debug'].lower() == 'true' else logging.ERROR)) + handler = logging.FileHandler(filename=datetime.now().strftime('logs/log%Y-%m-%d_%H-%M-%S.log'), encoding='utf-8', mode='w') + handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s')) + logger.addHandler(handler) + # setup client super().__init__(command_prefix=self.config['bot']['command_prefix'], case_insensitive=True) diff --git a/config_default.ini b/config_default.ini index 03910fd..f0ac6e5 100644 --- a/config_default.ini +++ b/config_default.ini @@ -2,6 +2,8 @@ token = myBotToken command_prefix = ! game_name = uninteresting.dev +debug = false +logging = true [guild] history_channel = 0 \ No newline at end of file diff --git a/run.py b/run.py index e6f8337..829c8fb 100644 --- a/run.py +++ b/run.py @@ -2,5 +2,4 @@ if __name__ == "__main__": bot = UninterestingBot() - bot.run() - + bot.run() \ No newline at end of file