From 69882af0bd49e479e672808267891788b7e602ae Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Sat, 9 Dec 2023 13:55:40 +0100 Subject: [PATCH] Added event logger --- bot/src/bot/config | 2 +- bot/src/bot/startup.py | 2 ++ .../core_extension_on_ready_event.py | 6 ++---- bot/src/bot_core/events/core_on_ready_event.py | 4 ++-- bot/src/bot_core/logging/event_logger.py | 15 +++++++++++++++ .../base/events/base_on_command_error_event.py | 4 ++-- .../base/events/base_on_guild_join_event.py | 4 ++-- .../base/events/base_on_member_join_event.py | 6 +++--- .../base/events/base_on_member_remove_event.py | 4 ++-- .../base/events/base_on_raw_reaction_add.py | 3 ++- .../base/events/base_on_raw_reaction_remove.py | 3 ++- .../base_on_scheduled_event_update_event.py | 3 ++- .../events/base_on_voice_state_update_event.py | 3 ++- ...se_on_voice_state_update_event_help_channel.py | 3 ++- ...ce_state_update_event_scheduled_event_bonus.py | 3 ++- .../modules/boot_log/boot_log_on_ready_event.py | 3 ++- .../config/events/config_on_ready_event.py | 4 ++-- .../level/events/level_on_member_join_event.py | 3 ++- .../events/level_on_raw_reaction_add_event.py | 3 ++- .../events/level_on_raw_reaction_remove_event.py | 3 ++- .../events/level_on_voice_state_update_event.py | 3 ++- 21 files changed, 55 insertions(+), 29 deletions(-) create mode 100644 bot/src/bot_core/logging/event_logger.py diff --git a/bot/src/bot/config b/bot/src/bot/config index 4669bf7c..be5b15f2 160000 --- a/bot/src/bot/config +++ b/bot/src/bot/config @@ -1 +1 @@ -Subproject commit 4669bf7c43c7aec368a1a1917ea92038c007944f +Subproject commit be5b15f227e7b2b12cc73c0edd7f6fa95dbdd52f diff --git a/bot/src/bot/startup.py b/bot/src/bot/startup.py index 0a5422d2..35e628f3 100644 --- a/bot/src/bot/startup.py +++ b/bot/src/bot/startup.py @@ -15,6 +15,7 @@ from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings from bot_core.logging.command_logger import CommandLogger from bot_core.logging.database_logger import DatabaseLogger +from bot_core.logging.event_logger import EventLogger from bot_core.logging.message_logger import MessageLogger from bot_core.logging.task_logger import TaskLogger from bot_data.db_context import DBContext @@ -45,6 +46,7 @@ class Startup(StartupABC): services.add_singleton(CustomFileLoggerABC, DatabaseLogger) services.add_singleton(CustomFileLoggerABC, MessageLogger) services.add_singleton(CustomFileLoggerABC, TaskLogger) + services.add_singleton(CustomFileLoggerABC, EventLogger) if self._feature_flags.get_flag(FeatureFlagsEnum.api_module): services.add_singleton(CustomFileLoggerABC, ApiLogger) diff --git a/bot/src/bot_core/core_extension/core_extension_on_ready_event.py b/bot/src/bot_core/core_extension/core_extension_on_ready_event.py index 277cf566..6b0621dc 100644 --- a/bot/src/bot_core/core_extension/core_extension_on_ready_event.py +++ b/bot/src/bot_core/core_extension/core_extension_on_ready_event.py @@ -1,20 +1,18 @@ -import asyncio - from cpl_core.configuration import ConfigurationABC -from cpl_core.logging import LoggerABC from cpl_discord.events import OnReadyABC from cpl_discord.service import DiscordBotServiceABC from cpl_translation import TranslatePipe from bot_core.abc.client_utils_abc import ClientUtilsABC from bot_core.environment_variables import MAINTENANCE +from bot_core.logging.event_logger import EventLogger class CoreExtensionOnReadyEvent(OnReadyABC): def __init__( self, config: ConfigurationABC, - logger: LoggerABC, + logger: EventLogger, bot: DiscordBotServiceABC, client_utils: ClientUtilsABC, t: TranslatePipe, diff --git a/bot/src/bot_core/events/core_on_ready_event.py b/bot/src/bot_core/events/core_on_ready_event.py index 10a88f9d..8dd915ba 100644 --- a/bot/src/bot_core/events/core_on_ready_event.py +++ b/bot/src/bot_core/events/core_on_ready_event.py @@ -1,15 +1,15 @@ -from cpl_core.logging import LoggerABC from cpl_discord.events import OnReadyABC from cpl_discord.service import DiscordBotServiceABC from cpl_translation import TranslatePipe from bot_core.abc.client_utils_abc import ClientUtilsABC +from bot_core.logging.event_logger import EventLogger class CoreOnReadyEvent(OnReadyABC): def __init__( self, - logger: LoggerABC, + logger: EventLogger, bot: DiscordBotServiceABC, client_utils: ClientUtilsABC, t: TranslatePipe, diff --git a/bot/src/bot_core/logging/event_logger.py b/bot/src/bot_core/logging/event_logger.py new file mode 100644 index 00000000..28fdde12 --- /dev/null +++ b/bot/src/bot_core/logging/event_logger.py @@ -0,0 +1,15 @@ +from cpl_core.configuration import ConfigurationABC +from cpl_core.environment import ApplicationEnvironmentABC +from cpl_core.time import TimeFormatSettings + +from bot_core.abc.custom_file_logger_abc import CustomFileLoggerABC + + +class EventLogger(CustomFileLoggerABC): + def __init__( + self, + config: ConfigurationABC, + time_format: TimeFormatSettings, + env: ApplicationEnvironmentABC, + ): + CustomFileLoggerABC.__init__(self, "Task", config, time_format, env) diff --git a/bot/src/modules/base/events/base_on_command_error_event.py b/bot/src/modules/base/events/base_on_command_error_event.py index d371a2aa..7511879b 100644 --- a/bot/src/modules/base/events/base_on_command_error_event.py +++ b/bot/src/modules/base/events/base_on_command_error_event.py @@ -1,7 +1,6 @@ import datetime import uuid -from cpl_core.logging import LoggerABC from cpl_core.time import TimeFormatSettings from cpl_discord.events.on_command_error_abc import OnCommandErrorABC from cpl_discord.service import DiscordBotServiceABC @@ -12,13 +11,14 @@ from discord.ext.commands import Context, CommandError from bot_core.abc.message_service_abc import MessageServiceABC from bot_core.exception.check_error import CheckError from bot_core.helper.event_checks import EventChecks +from bot_core.logging.event_logger import EventLogger from bot_data.model.technician_config import TechnicianConfig class BaseOnCommandErrorEvent(OnCommandErrorABC): def __init__( self, - logger: LoggerABC, + logger: EventLogger, bot: DiscordBotServiceABC, messenger: MessageServiceABC, tech_settings: TechnicianConfig, diff --git a/bot/src/modules/base/events/base_on_guild_join_event.py b/bot/src/modules/base/events/base_on_guild_join_event.py index 644fd194..627b8c3b 100644 --- a/bot/src/modules/base/events/base_on_guild_join_event.py +++ b/bot/src/modules/base/events/base_on_guild_join_event.py @@ -1,10 +1,10 @@ from cpl_core.database.context import DatabaseContextABC -from cpl_core.logging import LoggerABC from cpl_discord.events import OnGuildJoinABC from cpl_discord.service import DiscordBotServiceABC from discord import Guild from bot_core.helper.event_checks import EventChecks +from bot_core.logging.event_logger import EventLogger from bot_data.abc.server_config_repository_abc import ServerConfigRepositoryABC from bot_data.abc.server_repository_abc import ServerRepositoryABC from bot_data.model.server import Server @@ -14,7 +14,7 @@ from bot_data.service.seeder_service import SeederService class BaseOnGuildJoinEvent(OnGuildJoinABC): def __init__( self, - logger: LoggerABC, + logger: EventLogger, bot: DiscordBotServiceABC, servers: ServerRepositoryABC, server_config: ServerConfigRepositoryABC, diff --git a/bot/src/modules/base/events/base_on_member_join_event.py b/bot/src/modules/base/events/base_on_member_join_event.py index 63054277..4cd4f2e3 100644 --- a/bot/src/modules/base/events/base_on_member_join_event.py +++ b/bot/src/modules/base/events/base_on_member_join_event.py @@ -4,14 +4,15 @@ from typing import Union import discord from cpl_core.configuration import ConfigurationABC from cpl_core.database.context import DatabaseContextABC -from cpl_core.logging import LoggerABC from cpl_discord.events import OnMemberJoinABC from cpl_discord.service import DiscordBotServiceABC from cpl_translation import TranslatePipe from bot_core.abc.client_utils_abc import ClientUtilsABC from bot_core.abc.message_service_abc import MessageServiceABC +from bot_core.abc.permission_service_abc import PermissionServiceABC from bot_core.helper.event_checks import EventChecks +from bot_core.logging.event_logger import EventLogger from bot_data.abc.known_user_repository_abc import KnownUserRepositoryABC from bot_data.abc.server_repository_abc import ServerRepositoryABC from bot_data.abc.user_joined_server_repository_abc import UserJoinedServerRepositoryABC @@ -20,14 +21,13 @@ from bot_data.model.known_user import KnownUser from bot_data.model.server_config import ServerConfig from bot_data.model.user import User from bot_data.model.user_joined_server import UserJoinedServer -from bot_core.abc.permission_service_abc import PermissionServiceABC class BaseOnMemberJoinEvent(OnMemberJoinABC): def __init__( self, config: ConfigurationABC, - logger: LoggerABC, + logger: EventLogger, messenger: MessageServiceABC, permissions: PermissionServiceABC, db: DatabaseContextABC, diff --git a/bot/src/modules/base/events/base_on_member_remove_event.py b/bot/src/modules/base/events/base_on_member_remove_event.py index c32d9be6..c5eb70b0 100644 --- a/bot/src/modules/base/events/base_on_member_remove_event.py +++ b/bot/src/modules/base/events/base_on_member_remove_event.py @@ -4,12 +4,12 @@ from typing import Union import discord from cpl_core.configuration import ConfigurationABC from cpl_core.database.context import DatabaseContextABC -from cpl_core.logging import LoggerABC from cpl_discord.events import OnMemberRemoveABC from cpl_translation import TranslatePipe from bot_core.abc.message_service_abc import MessageServiceABC from bot_core.helper.event_checks import EventChecks +from bot_core.logging.event_logger import EventLogger from bot_data.abc.server_repository_abc import ServerRepositoryABC from bot_data.abc.user_joined_server_repository_abc import UserJoinedServerRepositoryABC from bot_data.abc.user_repository_abc import UserRepositoryABC @@ -20,7 +20,7 @@ class BaseOnMemberRemoveEvent(OnMemberRemoveABC): def __init__( self, config: ConfigurationABC, - logger: LoggerABC, + logger: EventLogger, db: DatabaseContextABC, message_service: MessageServiceABC, users: UserRepositoryABC, diff --git a/bot/src/modules/base/events/base_on_raw_reaction_add.py b/bot/src/modules/base/events/base_on_raw_reaction_add.py index 72e06099..7cab11b3 100644 --- a/bot/src/modules/base/events/base_on_raw_reaction_add.py +++ b/bot/src/modules/base/events/base_on_raw_reaction_add.py @@ -4,6 +4,7 @@ from cpl_discord.service import DiscordBotServiceABC from discord import RawReactionActionEvent from bot_core.helper.event_checks import EventChecks +from bot_core.logging.event_logger import EventLogger from bot_data.abc.auto_role_repository_abc import AutoRoleRepositoryABC from bot_data.abc.server_repository_abc import ServerRepositoryABC from modules.base.helper.base_reaction_handler import BaseReactionHandler @@ -12,7 +13,7 @@ from modules.base.helper.base_reaction_handler import BaseReactionHandler class BaseOnRawReactionAddEvent(OnRawReactionAddABC): def __init__( self, - logger: LoggerABC, + logger: EventLogger, bot: DiscordBotServiceABC, servers: ServerRepositoryABC, auto_roles: AutoRoleRepositoryABC, diff --git a/bot/src/modules/base/events/base_on_raw_reaction_remove.py b/bot/src/modules/base/events/base_on_raw_reaction_remove.py index 273fada1..35124df4 100644 --- a/bot/src/modules/base/events/base_on_raw_reaction_remove.py +++ b/bot/src/modules/base/events/base_on_raw_reaction_remove.py @@ -4,6 +4,7 @@ from cpl_discord.service import DiscordBotServiceABC from discord import RawReactionActionEvent from bot_core.helper.event_checks import EventChecks +from bot_core.logging.event_logger import EventLogger from bot_data.abc.auto_role_repository_abc import AutoRoleRepositoryABC from bot_data.abc.server_repository_abc import ServerRepositoryABC from modules.base.helper.base_reaction_handler import BaseReactionHandler @@ -12,7 +13,7 @@ from modules.base.helper.base_reaction_handler import BaseReactionHandler class BaseOnRawReactionRemoveEvent(OnRawReactionRemoveABC): def __init__( self, - logger: LoggerABC, + logger: EventLogger, bot: DiscordBotServiceABC, servers: ServerRepositoryABC, auto_roles: AutoRoleRepositoryABC, diff --git a/bot/src/modules/base/events/base_on_scheduled_event_update_event.py b/bot/src/modules/base/events/base_on_scheduled_event_update_event.py index a9000330..b12be8ac 100644 --- a/bot/src/modules/base/events/base_on_scheduled_event_update_event.py +++ b/bot/src/modules/base/events/base_on_scheduled_event_update_event.py @@ -5,6 +5,7 @@ from cpl_discord.service import DiscordBotServiceABC from discord import EventStatus from bot_core.helper.event_checks import EventChecks +from bot_core.logging.event_logger import EventLogger from modules.base.model.active_event import ActiveEvent from modules.base.service.event_service import EventService @@ -12,7 +13,7 @@ from modules.base.service.event_service import EventService class BaseOnScheduledEventUpdateEvent(OnScheduledEventUpdateABC): def __init__( self, - logger: LoggerABC, + logger: EventLogger, bot: DiscordBotServiceABC, events: EventService, ): diff --git a/bot/src/modules/base/events/base_on_voice_state_update_event.py b/bot/src/modules/base/events/base_on_voice_state_update_event.py index 32036120..87601b78 100644 --- a/bot/src/modules/base/events/base_on_voice_state_update_event.py +++ b/bot/src/modules/base/events/base_on_voice_state_update_event.py @@ -8,6 +8,7 @@ from cpl_core.logging import LoggerABC from cpl_discord.events import OnVoiceStateUpdateABC from bot_core.helper.event_checks import EventChecks +from bot_core.logging.event_logger import EventLogger from bot_data.abc.known_user_repository_abc import KnownUserRepositoryABC from bot_data.abc.server_repository_abc import ServerRepositoryABC from bot_data.abc.user_joined_server_repository_abc import UserJoinedServerRepositoryABC @@ -25,7 +26,7 @@ class BaseOnVoiceStateUpdateEvent(OnVoiceStateUpdateABC): def __init__( self, config: ConfigurationABC, - logger: LoggerABC, + logger: EventLogger, servers: ServerRepositoryABC, known_users: KnownUserRepositoryABC, users: UserRepositoryABC, diff --git a/bot/src/modules/base/events/base_on_voice_state_update_event_help_channel.py b/bot/src/modules/base/events/base_on_voice_state_update_event_help_channel.py index 8ae95da8..2fbf883b 100644 --- a/bot/src/modules/base/events/base_on_voice_state_update_event_help_channel.py +++ b/bot/src/modules/base/events/base_on_voice_state_update_event_help_channel.py @@ -6,6 +6,7 @@ from cpl_translation import TranslatePipe from bot_core.abc.message_service_abc import MessageServiceABC from bot_core.helper.event_checks import EventChecks +from bot_core.logging.event_logger import EventLogger from bot_data.abc.server_repository_abc import ServerRepositoryABC from bot_data.model.server_config import ServerConfig from bot_core.abc.permission_service_abc import PermissionServiceABC @@ -15,7 +16,7 @@ class BaseOnVoiceStateUpdateEventHelpChannel(OnVoiceStateUpdateABC): def __init__( self, config: ConfigurationABC, - logger: LoggerABC, + logger: EventLogger, servers: ServerRepositoryABC, permissions: PermissionServiceABC, message_service: MessageServiceABC, diff --git a/bot/src/modules/base/events/base_on_voice_state_update_event_scheduled_event_bonus.py b/bot/src/modules/base/events/base_on_voice_state_update_event_scheduled_event_bonus.py index b18af00b..ae20bfae 100644 --- a/bot/src/modules/base/events/base_on_voice_state_update_event_scheduled_event_bonus.py +++ b/bot/src/modules/base/events/base_on_voice_state_update_event_scheduled_event_bonus.py @@ -5,6 +5,7 @@ from cpl_core.logging import LoggerABC from cpl_discord.events import OnVoiceStateUpdateABC from bot_core.helper.event_checks import EventChecks +from bot_core.logging.event_logger import EventLogger from bot_data.abc.server_repository_abc import ServerRepositoryABC from bot_data.abc.user_repository_abc import UserRepositoryABC from modules.base.service.event_service import EventService @@ -14,7 +15,7 @@ class BaseOnVoiceStateUpdateEventScheduledEventBonus(OnVoiceStateUpdateABC): def __init__( self, config: ConfigurationABC, - logger: LoggerABC, + logger: EventLogger, servers: ServerRepositoryABC, users: UserRepositoryABC, events: EventService, diff --git a/bot/src/modules/boot_log/boot_log_on_ready_event.py b/bot/src/modules/boot_log/boot_log_on_ready_event.py index 0c5161fd..9889dc18 100644 --- a/bot/src/modules/boot_log/boot_log_on_ready_event.py +++ b/bot/src/modules/boot_log/boot_log_on_ready_event.py @@ -10,6 +10,7 @@ from discord import guild from bot_core.abc.message_service_abc import MessageServiceABC from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings +from bot_core.logging.event_logger import EventLogger from bot_data.model.server_config import ServerConfig from bot_data.model.technician_config import TechnicianConfig @@ -18,7 +19,7 @@ class BootLogOnReadyEvent(OnReadyABC): def __init__( self, config: ConfigurationABC, - logger: LoggerABC, + logger: EventLogger, bot: DiscordBotServiceABC, message_service: MessageServiceABC, translate: TranslatePipe, diff --git a/bot/src/modules/config/events/config_on_ready_event.py b/bot/src/modules/config/events/config_on_ready_event.py index 699063d6..8b7f1a67 100644 --- a/bot/src/modules/config/events/config_on_ready_event.py +++ b/bot/src/modules/config/events/config_on_ready_event.py @@ -1,8 +1,8 @@ from cpl_core.configuration import ConfigurationABC -from cpl_core.logging import LoggerABC from cpl_discord.events import OnReadyABC from cpl_discord.service import DiscordBotServiceABC +from bot_core.logging.event_logger import EventLogger from bot_core.service.config_service import ConfigService from bot_core.service.data_integrity_service import DataIntegrityService from bot_data.abc.server_repository_abc import ServerRepositoryABC @@ -12,7 +12,7 @@ class ConfigOnReadyEvent(OnReadyABC): def __init__( self, config: ConfigurationABC, - logger: LoggerABC, + logger: EventLogger, bot: DiscordBotServiceABC, servers: ServerRepositoryABC, config_service: ConfigService, diff --git a/bot/src/modules/level/events/level_on_member_join_event.py b/bot/src/modules/level/events/level_on_member_join_event.py index 38326ed3..40428732 100644 --- a/bot/src/modules/level/events/level_on_member_join_event.py +++ b/bot/src/modules/level/events/level_on_member_join_event.py @@ -5,13 +5,14 @@ from cpl_discord.events import OnMemberJoinABC from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings from bot_core.helper.event_checks import EventChecks +from bot_core.logging.event_logger import EventLogger from bot_core.logging.message_logger import MessageLogger from bot_data.model.server_config import ServerConfig from modules.level.service.level_service import LevelService class LevelOnMemberJoinEvent(OnMemberJoinABC): - def __init__(self, config: ConfigurationABC, logger: MessageLogger, level: LevelService): + def __init__(self, config: ConfigurationABC, logger: EventLogger, level: LevelService): OnMemberJoinABC.__init__(self) self._config = config self._logger = logger diff --git a/bot/src/modules/level/events/level_on_raw_reaction_add_event.py b/bot/src/modules/level/events/level_on_raw_reaction_add_event.py index 341a0a21..259910f7 100644 --- a/bot/src/modules/level/events/level_on_raw_reaction_add_event.py +++ b/bot/src/modules/level/events/level_on_raw_reaction_add_event.py @@ -7,6 +7,7 @@ from discord import RawReactionActionEvent from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings from bot_core.helper.event_checks import EventChecks +from bot_core.logging.event_logger import EventLogger from bot_data.model.server_config import ServerConfig from modules.level.service.level_service import LevelService @@ -15,7 +16,7 @@ class LevelOnRawReactionAddEvent(OnRawReactionAddABC): def __init__( self, config: ConfigurationABC, - logger: LoggerABC, + logger: EventLogger, bot: DiscordBotServiceABC, level: LevelService, ): diff --git a/bot/src/modules/level/events/level_on_raw_reaction_remove_event.py b/bot/src/modules/level/events/level_on_raw_reaction_remove_event.py index 1c04f19b..d44cf96d 100644 --- a/bot/src/modules/level/events/level_on_raw_reaction_remove_event.py +++ b/bot/src/modules/level/events/level_on_raw_reaction_remove_event.py @@ -7,6 +7,7 @@ from discord import RawReactionActionEvent from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings from bot_core.helper.event_checks import EventChecks +from bot_core.logging.event_logger import EventLogger from bot_data.model.server_config import ServerConfig from modules.level.service.level_service import LevelService @@ -15,7 +16,7 @@ class LevelOnRawReactionRemoveEvent(OnRawReactionRemoveABC): def __init__( self, config: ConfigurationABC, - logger: LoggerABC, + logger: EventLogger, bot: DiscordBotServiceABC, level: LevelService, ): diff --git a/bot/src/modules/level/events/level_on_voice_state_update_event.py b/bot/src/modules/level/events/level_on_voice_state_update_event.py index f9bb2bf2..079b2ffe 100644 --- a/bot/src/modules/level/events/level_on_voice_state_update_event.py +++ b/bot/src/modules/level/events/level_on_voice_state_update_event.py @@ -6,12 +6,13 @@ from cpl_discord.events import OnVoiceStateUpdateABC from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings from bot_core.helper.event_checks import EventChecks +from bot_core.logging.event_logger import EventLogger from bot_data.model.server_config import ServerConfig from modules.level.service.level_service import LevelService class LevelOnVoiceStateUpdateEvent(OnVoiceStateUpdateABC): - def __init__(self, config: ConfigurationABC, logger: LoggerABC, level: LevelService): + def __init__(self, config: ConfigurationABC, logger: EventLogger, level: LevelService): OnVoiceStateUpdateABC.__init__(self) self._config = config self._logger = logger