1
Fork 0
mirror of https://github.com/allthingslinux/tux.git synced 2024-10-03 00:53:12 +00:00

style fixes by ruff

This commit is contained in:
ExploitDemon 2024-01-09 02:13:02 +00:00 committed by github-actions[bot]
parent ea4725a887
commit 09d7de86a5

View file

@ -1,5 +1,6 @@
import os
import logging
import os
import colorlog
from discord.ext import commands
@ -27,9 +28,7 @@ from discord.ext import commands
class TuxLogger(logging.Logger):
def __init__(self,
name,
project_logging_level=logging.INFO):
def __init__(self, name, project_logging_level=logging.INFO):
"""
Constructor for the custom logger class.
@ -44,20 +43,20 @@ class TuxLogger(logging.Logger):
"""
Set up the logging configuration for the custom logger.
"""
log_format = '%(asctime)s [%(log_color)s%(levelname)s%(reset)s] [%(name)s]: %(message)s'
log_dir = 'logs'
log_format = (
"%(asctime)s [%(log_color)s%(levelname)s%(reset)s] [%(name)s]: %(message)s"
)
log_dir = "logs"
os.makedirs(log_dir, exist_ok=True)
handler = colorlog.StreamHandler()
handler.setFormatter(colorlog.ColoredFormatter(log_format))
self.addHandler(handler)
file_handler = logging.FileHandler(
os.path.join(log_dir, 'bot.log'),
mode='a'
file_handler = logging.FileHandler(os.path.join(log_dir, "bot.log"), mode="a")
file_handler.setFormatter(
logging.Formatter("%(asctime)s [%(levelname)s] [%(name)s]: %(message)s")
)
file_handler.setFormatter(logging.Formatter(
'%(asctime)s [%(levelname)s] [%(name)s]: %(message)s'))
self.addHandler(file_handler)
def _log_to_file(self, level, message, caller_module):
@ -71,12 +70,11 @@ class TuxLogger(logging.Logger):
"""
file_handler = logging.FileHandler(
os.path.join('logs', f"{caller_module}.log"),
mode='a'
os.path.join("logs", f"{caller_module}.log"), mode="a"
)
file_handler.setFormatter(
logging.Formatter(
f'%(asctime)s [%(levelname)s] [{caller_module}]: %(message)s'
f"%(asctime)s [%(levelname)s] [{caller_module}]: %(message)s"
)
)
self.addHandler(file_handler)
@ -103,9 +101,7 @@ class TuxLogger(logging.Logger):
class LoggingCog(commands.Cog):
def __init__(self,
bot,
discord_logging_level=logging.WARNING):
def __init__(self, bot, discord_logging_level=logging.WARNING):
"""
Constructor for the LoggingCog class.
@ -116,16 +112,16 @@ class LoggingCog(commands.Cog):
self.bot = bot
self.discord_logging_level = discord_logging_level
discord_logger = logging.getLogger('discord')
discord_logger = logging.getLogger("discord")
discord_logger.setLevel(self.discord_logging_level)
logger = TuxLogger(__name__)
async def setup(bot,
project_logging_level=logging.DEBUG,
discord_logging_level=logging.WARNING):
async def setup(
bot, project_logging_level=logging.DEBUG, discord_logging_level=logging.WARNING
):
"""
Asynchronous function to set up the LoggingCog and add it to the Discord bot.
@ -135,9 +131,6 @@ async def setup(bot,
- discord_logging_level: The logging level for the Discord library (default is WARNING).
"""
global logger
log_cog = LoggingCog(
bot,
discord_logging_level
)
log_cog = LoggingCog(bot, discord_logging_level)
logger.setLevel(project_logging_level)
await bot.add_cog(log_cog)