Moved logging to bot.py and fixed config issues
parent
7cb259e65f
commit
67640948d8
|
@ -3,12 +3,12 @@ import configparser
|
|||
import os
|
||||
|
||||
|
||||
def create_config(config):
|
||||
def create_config(config, path):
|
||||
config['Discord'] = {'Token': '',
|
||||
'Status': '',
|
||||
'Prefix': '?',
|
||||
'Bot_Mod': ''
|
||||
'Error_Users: '''
|
||||
'Bot_Mod': '',
|
||||
'Error_Users': ''
|
||||
}
|
||||
config['SQL'] = {'Dialect+Driver': 'mysql+mysqldb',
|
||||
'Username': '',
|
||||
|
@ -29,7 +29,7 @@ def create_config(config):
|
|||
}
|
||||
config['Special Names'] = {}
|
||||
|
||||
with open('GeoffreyConfig.ini', 'w') as configfile:
|
||||
with open('{}/GeoffreyConfig.ini'.format(path), 'w') as configfile:
|
||||
config.write(configfile)
|
||||
|
||||
|
||||
|
@ -39,7 +39,7 @@ def read_config():
|
|||
config.read_file(codecs.open("{}/GeoffreyConfig.ini".format(path), "r", "utf8"))
|
||||
|
||||
if len(config.sections()) == 0:
|
||||
create_config(config)
|
||||
create_config(config, path)
|
||||
print("GeoffreyConfig.ini generated.")
|
||||
quit(0)
|
||||
|
||||
|
@ -86,5 +86,4 @@ class Config:
|
|||
|
||||
return engine_args.format(driver, username, password, host, port, database_name)
|
||||
|
||||
|
||||
bot_config = Config()
|
||||
|
|
|
@ -11,34 +11,6 @@ from sys import stdout
|
|||
from geoffrey import bot
|
||||
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__':
|
||||
print("Starting logging...")
|
||||
setup_logging()
|
||||
print("Starting bot...")
|
||||
bot.start_bot()
|
||||
|
|
|
@ -6,6 +6,10 @@ from discord.ext import commands
|
|||
from discord.utils import oauth_url
|
||||
from sqlalchemy.exc import OperationalError
|
||||
|
||||
import logging.handlers as handlers
|
||||
from sys import stdout
|
||||
|
||||
|
||||
from geoffrey.BotConfig import bot_config
|
||||
from geoffrey.BotErrors import *
|
||||
from geoffrey.Commands import Commands
|
||||
|
@ -134,9 +138,34 @@ async def username_update():
|
|||
session.close()
|
||||
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():
|
||||
try:
|
||||
|
||||
setup_logging()
|
||||
Commands()
|
||||
for extension in extensions:
|
||||
try:
|
||||
|
|
Loading…
Reference in New Issue