Skip to content
This repository has been archived by the owner on Dec 27, 2022. It is now read-only.

Commit

Permalink
feat: add logging
Browse files Browse the repository at this point in the history
  • Loading branch information
TitusKirch committed Jan 17, 2020
1 parent e5bbfd2 commit 290fab2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
10 changes: 10 additions & 0 deletions bot.py
@@ -1,4 +1,6 @@
import discord
import logging
from datetime import datetime
from utilities import getConfig
from discord.ext import commands

Expand All @@ -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)

Expand Down
2 changes: 2 additions & 0 deletions config_default.ini
Expand Up @@ -2,6 +2,8 @@
token = myBotToken
command_prefix = !
game_name = uninteresting.dev
debug = false
logging = true

[guild]
history_channel = 0
3 changes: 1 addition & 2 deletions run.py
Expand Up @@ -2,5 +2,4 @@

if __name__ == "__main__":
bot = UninterestingBot()
bot.run()

bot.run()

0 comments on commit 290fab2

Please sign in to comment.