Moved logging to bot.py and fixed config issues

doc_update
Joey Hines 2018-08-29 10:08:21 -05:00
parent 7cb259e65f
commit 67640948d8
3 changed files with 34 additions and 34 deletions

View File

@ -3,12 +3,12 @@ import configparser
import os import os
def create_config(config): def create_config(config, path):
config['Discord'] = {'Token': '', config['Discord'] = {'Token': '',
'Status': '', 'Status': '',
'Prefix': '?', 'Prefix': '?',
'Bot_Mod': '' 'Bot_Mod': '',
'Error_Users: ''' 'Error_Users': ''
} }
config['SQL'] = {'Dialect+Driver': 'mysql+mysqldb', config['SQL'] = {'Dialect+Driver': 'mysql+mysqldb',
'Username': '', 'Username': '',
@ -29,7 +29,7 @@ def create_config(config):
} }
config['Special Names'] = {} config['Special Names'] = {}
with open('GeoffreyConfig.ini', 'w') as configfile: with open('{}/GeoffreyConfig.ini'.format(path), 'w') as configfile:
config.write(configfile) config.write(configfile)
@ -39,7 +39,7 @@ def read_config():
config.read_file(codecs.open("{}/GeoffreyConfig.ini".format(path), "r", "utf8")) config.read_file(codecs.open("{}/GeoffreyConfig.ini".format(path), "r", "utf8"))
if len(config.sections()) == 0: if len(config.sections()) == 0:
create_config(config) create_config(config, path)
print("GeoffreyConfig.ini generated.") print("GeoffreyConfig.ini generated.")
quit(0) quit(0)
@ -86,5 +86,4 @@ class Config:
return engine_args.format(driver, username, password, host, port, database_name) return engine_args.format(driver, username, password, host, port, database_name)
bot_config = Config() bot_config = Config()

View File

@ -11,34 +11,6 @@ from sys import stdout
from geoffrey import bot from geoffrey import bot
from geoffrey.BotConfig import bot_config from geoffrey.BotConfig import bot_config
def setup_logging():
discord_logger = logging.getLogger('discord')
discord_logger.setLevel(logging.INFO)
sql_logger = logging.getLogger('sqlalchemy.engine')
sql_logger.setLevel(logging.INFO)
bot_info_logger = logging.getLogger('geoffrey.bot')
bot_info_logger.setLevel(logging.INFO)
handler = handlers.TimedRotatingFileHandler(filename='Geoffrey.log', when='D',
interval=bot_config.rotation_duration, backupCount=bot_config.count,
encoding='utf-8')
handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s'))
console = logging.StreamHandler(stdout)
console.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s'))
discord_logger.addHandler(handler)
sql_logger.addHandler(handler)
bot_info_logger.addHandler(handler)
bot_info_logger.addHandler(console)
if __name__ == '__main__': if __name__ == '__main__':
print("Starting logging...")
setup_logging()
print("Starting bot...") print("Starting bot...")
bot.start_bot() bot.start_bot()

View File

@ -6,6 +6,10 @@ from discord.ext import commands
from discord.utils import oauth_url from discord.utils import oauth_url
from sqlalchemy.exc import OperationalError from sqlalchemy.exc import OperationalError
import logging.handlers as handlers
from sys import stdout
from geoffrey.BotConfig import bot_config from geoffrey.BotConfig import bot_config
from geoffrey.BotErrors import * from geoffrey.BotErrors import *
from geoffrey.Commands import Commands from geoffrey.Commands import Commands
@ -134,9 +138,34 @@ async def username_update():
session.close() session.close()
await asyncio.sleep(600) await asyncio.sleep(600)
def setup_logging():
discord_logger = logging.getLogger('discord')
discord_logger.setLevel(logging.INFO)
sql_logger = logging.getLogger('sqlalchemy.engine')
sql_logger.setLevel(logging.INFO)
bot_info_logger = logging.getLogger('geoffrey.bot')
bot_info_logger.setLevel(logging.INFO)
handler = handlers.TimedRotatingFileHandler(filename='Geoffrey.log', when='D',
interval=bot_config.rotation_duration, backupCount=bot_config.count,
encoding='utf-8')
handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s'))
console = logging.StreamHandler(stdout)
console.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s'))
discord_logger.addHandler(handler)
sql_logger.addHandler(handler)
bot_info_logger.addHandler(handler)
bot_info_logger.addHandler(console)
def start_bot(): def start_bot():
try: try:
setup_logging()
Commands() Commands()
for extension in extensions: for extension in extensions:
try: try: