Log file path can now be set in the config and all errors are now logged.
parent
bcaf65f9ee
commit
6e6ba39fab
|
@ -19,7 +19,8 @@ def create_config(config, path):
|
||||||
config['Minecraft'] = {'Dynmap_Url': '',
|
config['Minecraft'] = {'Dynmap_Url': '',
|
||||||
'World_Name': '',
|
'World_Name': '',
|
||||||
}
|
}
|
||||||
config['Logging'] = {'Count': '7',
|
config['Logging'] = {'Log_Path': '',
|
||||||
|
'Count': '7',
|
||||||
'Rotation_Duration': '1'
|
'Rotation_Duration': '1'
|
||||||
}
|
}
|
||||||
config['Special Names'] = {}
|
config['Special Names'] = {}
|
||||||
|
@ -58,6 +59,7 @@ class Config:
|
||||||
|
|
||||||
self.dynmap_url = self.config['Minecraft']['Dynmap_Url']
|
self.dynmap_url = self.config['Minecraft']['Dynmap_Url']
|
||||||
|
|
||||||
|
self.log_path = self.config['Logging']['log_path']
|
||||||
self.count = int(self.config['Logging']['Count'])
|
self.count = int(self.config['Logging']['Count'])
|
||||||
self.rotation_duration = int(self.config['Logging']['Rotation_Duration'])
|
self.rotation_duration = int(self.config['Logging']['Rotation_Duration'])
|
||||||
self.special_name_list = dict(self.config.items('Special Names'))
|
self.special_name_list = dict(self.config.items('Special Names'))
|
||||||
|
|
|
@ -107,10 +107,10 @@ class GeoffreyBot(commands.Bot):
|
||||||
if error_str is '':
|
if error_str is '':
|
||||||
await self.send_error_message(
|
await self.send_error_message(
|
||||||
'Geoffrey encountered unhandled exception: {}. Context:'.format(error, ctx.args))
|
'Geoffrey encountered unhandled exception: {}. Context:'.format(error, ctx.args))
|
||||||
|
|
||||||
logger.error("Geoffrey encountered unhandled exception: %s", error)
|
|
||||||
error_str = bad_error_message.format(ctx.invoked_with)
|
error_str = bad_error_message.format(ctx.invoked_with)
|
||||||
|
|
||||||
|
logger.error("Geoffrey encountered exception: %s", error)
|
||||||
|
|
||||||
await self.send_message(ctx.message.channel, '{} **Error Running Command:** {}'.format(
|
await self.send_message(ctx.message.channel, '{} **Error Running Command:** {}'.format(
|
||||||
ctx.message.author.mention, error_str))
|
ctx.message.author.mention, error_str))
|
||||||
|
|
||||||
|
@ -146,16 +146,16 @@ async def username_update(bot):
|
||||||
|
|
||||||
|
|
||||||
def setup_logging(config):
|
def setup_logging(config):
|
||||||
|
|
||||||
discord_logger = logging.getLogger('discord')
|
discord_logger = logging.getLogger('discord')
|
||||||
discord_logger.setLevel(logging.INFO)
|
discord_logger.setLevel(logging.INFO)
|
||||||
sql_logger = logging.getLogger('sqlalchemy.engine')
|
sql_logger = logging.getLogger('sqlalchemy.engine')
|
||||||
sql_logger.setLevel(logging.INFO)
|
sql_logger.setLevel(logging.INFO)
|
||||||
bot_info_logger = logging.getLogger('geoffrey.bot')
|
bot_info_logger = logging.getLogger('geoffrey.bot')
|
||||||
bot_info_logger.setLevel(logging.INFO)
|
bot_info_logger.setLevel(logging.INFO)
|
||||||
|
log_path = path.abspath(config.log_path)
|
||||||
|
|
||||||
handler = handlers.TimedRotatingFileHandler(filename="{}/Geoffrey.log".format(path.dirname(path.abspath(__file__))),
|
handler = handlers.TimedRotatingFileHandler(filename="{}/Geoffrey.log".format(log_path), when='D',
|
||||||
when='D', interval=config.rotation_duration, backupCount=config.count,
|
interval=config.rotation_duration, backupCount=config.count,
|
||||||
encoding='utf-8')
|
encoding='utf-8')
|
||||||
|
|
||||||
handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s'))
|
handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s'))
|
||||||
|
|
|
@ -131,7 +131,6 @@ class Search_Commands:
|
||||||
"""
|
"""
|
||||||
Displays all your locations in the database
|
Displays all your locations in the database
|
||||||
"""
|
"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
loc_str = self.bot.bot_commands.me(discord_uuid=ctx.message.author.id)
|
loc_str = self.bot.bot_commands.me(discord_uuid=ctx.message.author.id)
|
||||||
await self.bot.say('{}, here are your locations in the database: \n {}'.format(ctx.message.author.mention,
|
await self.bot.say('{}, here are your locations in the database: \n {}'.format(ctx.message.author.mention,
|
||||||
|
|
Loading…
Reference in New Issue