feat(moderation): improved logging
All checks were successful
Pylint / Pylint (push) Successful in 1m13s
All checks were successful
Pylint / Pylint (push) Successful in 1m13s
This commit is contained in:
parent
da469e7d35
commit
6eb086f8cb
1 changed files with 12 additions and 6 deletions
|
@ -29,6 +29,12 @@ class Moderation(commands.Cog):
|
|||
)
|
||||
disable_dateutil()
|
||||
self.handle_expiry.start() # pylint: disable=no-member
|
||||
self.logger = logging.getLogger('red.seaswimmerthefsh.moderation')
|
||||
handler = logging.StreamHandler()
|
||||
handler.setLevel(logging.INFO)
|
||||
formatter = logging.Formatter('[%(levelname)s] %(name)s: %(message)s')
|
||||
handler.setFormatter(formatter)
|
||||
self.logger.addHandler(handler)
|
||||
|
||||
async def cog_load(self):
|
||||
"""This method prepares the database schema for all of the guilds the bot is currently in."""
|
||||
|
@ -39,7 +45,7 @@ class Moderation(commands.Cog):
|
|||
'mysql_password'
|
||||
])
|
||||
if conf:
|
||||
logging.fatal("Failed to create tables, due to MySQL connection configuration being unset.")
|
||||
self.logger.fatal("Failed to create tables, due to MySQL connection configuration being unset.")
|
||||
return
|
||||
guilds: list[discord.Guild] = self.bot.guilds
|
||||
try:
|
||||
|
@ -61,7 +67,7 @@ class Moderation(commands.Cog):
|
|||
'mysql_password'
|
||||
])
|
||||
if conf:
|
||||
logging.error("Failed to create a table for %s, due to MySQL connection configuration being unset.", guild.id)
|
||||
self.logger.error("Failed to create a table for %s, due to MySQL connection configuration being unset.", guild.id)
|
||||
return
|
||||
try:
|
||||
await self.create_guild_table(guild)
|
||||
|
@ -120,7 +126,7 @@ class Moderation(commands.Cog):
|
|||
)
|
||||
return connection
|
||||
except mysql.connector.ProgrammingError as e:
|
||||
logging.fatal("Unable to access the MySQL database!\nError:\n%s", e.msg)
|
||||
self.logger.fatal("Unable to access the MySQL database!\nError:\n%s", e.msg)
|
||||
raise ConnectionRefusedError(f"Unable to access the MySQL Database!\n{e.msg}") from e
|
||||
|
||||
def generate_dict(self, result):
|
||||
|
@ -145,7 +151,7 @@ class Moderation(commands.Cog):
|
|||
cursor = database.cursor()
|
||||
try:
|
||||
cursor.execute(f"SELECT * FROM `moderation_{guild.id}`")
|
||||
logging.info("MySQL Table exists for server %s (%s)", guild.name, guild.id)
|
||||
self.logger.info("MySQL Table exists for server %s (%s)", guild.name, guild.id)
|
||||
except mysql.connector.errors.ProgrammingError:
|
||||
query = f"""
|
||||
CREATE TABLE `moderation_{guild.id}` (
|
||||
|
@ -173,7 +179,7 @@ class Moderation(commands.Cog):
|
|||
cursor.execute(insert_query, insert_values)
|
||||
database.commit()
|
||||
database.close()
|
||||
logging.info("MySQL Table (moderation_%s) created for %s (%s)", guild.id, guild.name, guild.id)
|
||||
self.logger.info("MySQL Table (moderation_%s) created for %s (%s)", guild.id, guild.name, guild.id)
|
||||
else:
|
||||
database.close()
|
||||
return
|
||||
|
@ -201,7 +207,7 @@ class Moderation(commands.Cog):
|
|||
cursor.execute(sql, val)
|
||||
database.commit()
|
||||
database.close()
|
||||
logging.debug("MySQL row inserted into moderation_%s!\n%s, %s, %s, %s, %s, %s, %s, %s, 0, NULL, NULL, 0", guild_id, moderation_id, timestamp, moderation_type, target_id, author_id, duration, end_timestamp, reason)
|
||||
self.logger.debug("MySQL row inserted into moderation_%s!\n%s, %s, %s, %s, %s, %s, %s, %s, 0, NULL, NULL, 0", guild_id, moderation_id, timestamp, moderation_type, target_id, author_id, duration, end_timestamp, reason)
|
||||
|
||||
async def get_next_case_number(self, guild_id: str, cursor = None):
|
||||
"""This method returns the next case number from the MySQL table for a specific guild."""
|
||||
|
|
Loading…
Reference in a new issue