Improved logging
This commit is contained in:
		| @@ -1,16 +1,8 @@ | ||||
| import datetime | ||||
| import traceback | ||||
| import uuid | ||||
|  | ||||
| from cpl_core.time import TimeFormatSettings | ||||
| from cpl_discord.events import OnCommandABC | ||||
| from cpl_discord.service import DiscordBotServiceABC | ||||
| from cpl_translation import TranslatePipe | ||||
| from discord.ext import commands | ||||
| from discord.ext.commands import Context, CommandError | ||||
|  | ||||
| from cpl_core.logging import LoggerABC | ||||
| from cpl_discord.events.on_command_error_abc import OnCommandErrorABC | ||||
| from discord.ext.commands import Context | ||||
|  | ||||
| from bot_core.abc.message_service_abc import MessageServiceABC | ||||
| from bot_core.configuration.bot_settings import BotSettings | ||||
| @@ -37,5 +29,5 @@ class BaseOnCommandEvent(OnCommandABC): | ||||
|         self._t = translate | ||||
|  | ||||
|     async def on_command(self, ctx: Context): | ||||
|         self._logger.warn(__name__, f'Received command afk {ctx}') | ||||
|         print('\n', ctx.command) | ||||
|         pass | ||||
|   | ||||
| @@ -2,10 +2,11 @@ from typing import Optional | ||||
|  | ||||
| import discord | ||||
| from cpl_core.database.context import DatabaseContextABC | ||||
| from cpl_core.logging import LoggerABC | ||||
| from cpl_discord.events import OnMessageABC | ||||
| from cpl_discord.service import DiscordBotServiceABC | ||||
|  | ||||
| from bot_core.helper.log_message_helper import LogMessageHelper | ||||
| from bot_core.logging.message_logger import MessageLogger | ||||
| from bot_data.abc.client_repository_abc import ClientRepositoryABC | ||||
| from bot_data.abc.server_repository_abc import ServerRepositoryABC | ||||
| from bot_data.abc.user_repository_abc import UserRepositoryABC | ||||
| @@ -18,7 +19,7 @@ class BaseOnMessageEvent(OnMessageABC): | ||||
|  | ||||
|     def __init__( | ||||
|             self, | ||||
|             logger: LoggerABC, | ||||
|             logger: MessageLogger, | ||||
|             bhs: BaseHelperABC, | ||||
|             db: DatabaseContextABC, | ||||
|             bot: DiscordBotServiceABC, | ||||
| @@ -71,6 +72,7 @@ class BaseOnMessageEvent(OnMessageABC): | ||||
|  | ||||
|     async def on_message(self, message: discord.Message): | ||||
|         self._logger.debug(__name__, f'Module {type(self)} started') | ||||
|         self._logger.debug(__name__, f'Received message: {LogMessageHelper.get_log_string(message)}') | ||||
|         if message is None or message.guild is None: | ||||
|             return | ||||
|         self._append_received_message_count(message.guild.id) | ||||
|   | ||||
| @@ -42,12 +42,12 @@ class BootLogOnReadyEvent(OnReadyABC): | ||||
|             # print warning if initialisation took too long | ||||
|             if init_time >= 30: | ||||
|                 self._logger.warn( | ||||
|                     __name__, 'It takes long time to start the bot!') | ||||
|                     __name__, 'It takes too long to start the bot!') | ||||
|  | ||||
|             # print error if initialisation took way too long | ||||
|             elif init_time >= 90: | ||||
|                 self._logger.error( | ||||
|                     __name__, 'It takes very long time to start the bot!!!') | ||||
|                     __name__, 'It takes far too long to start the bot!!!') | ||||
|         except Exception as e: | ||||
|             self._logger.error(__name__, 'Init time calculation failed', e) | ||||
|             return | ||||
|   | ||||
| @@ -6,6 +6,7 @@ from cpl_core.dependency_injection import ServiceProviderABC | ||||
| from cpl_core.logging import LoggerABC | ||||
|  | ||||
| from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings | ||||
| from bot_core.logging.database_logger import DatabaseLogger | ||||
| from bot_data.service.migration_service import MigrationService | ||||
|  | ||||
|  | ||||
| @@ -18,7 +19,7 @@ class DatabaseExtension(ApplicationExtensionABC): | ||||
|         feature_flags: FeatureFlagsSettings = config.get_configuration(FeatureFlagsSettings) | ||||
|         if not feature_flags.database_module: | ||||
|             return | ||||
|         logger: LoggerABC = services.get_service(LoggerABC) | ||||
|         logger: LoggerABC = services.get_service(DatabaseLogger) | ||||
|         logger.debug(__name__, 'Database extension started') | ||||
|         config.add_configuration('Database_StartTime', str(datetime.now())) | ||||
|         migrations: MigrationService = services.get_service(MigrationService) | ||||
|   | ||||
| @@ -4,10 +4,10 @@ from datetime import datetime, timedelta | ||||
| 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 OnReadyABC | ||||
| from cpl_discord.service import DiscordBotServiceABC | ||||
|  | ||||
| from bot_core.logging.database_logger import DatabaseLogger | ||||
| from bot_core.pipes.date_time_offset_pipe import DateTimeOffsetPipe | ||||
| from bot_data.abc.client_repository_abc import ClientRepositoryABC | ||||
| from bot_data.abc.known_user_repository_abc import KnownUserRepositoryABC | ||||
| @@ -29,7 +29,7 @@ class DatabaseOnReadyEvent(OnReadyABC): | ||||
|     def __init__( | ||||
|         self, | ||||
|         config: ConfigurationABC, | ||||
|         logger: LoggerABC, | ||||
|         logger: DatabaseLogger, | ||||
|         bot: DiscordBotServiceABC, | ||||
|         db_context: DatabaseContextABC, | ||||
|         server_repo: ServerRepositoryABC, | ||||
| @@ -65,12 +65,12 @@ class DatabaseOnReadyEvent(OnReadyABC): | ||||
|             # print warning if initialisation took too long | ||||
|             if init_time >= 30: | ||||
|                 self._logger.warn( | ||||
|                     __name__, 'It takes long time to start the bot!') | ||||
|                     __name__, 'It takes too long to prepare the database!') | ||||
|  | ||||
|             # print error if initialisation took way too long | ||||
|             elif init_time >= 90: | ||||
|                 self._logger.error( | ||||
|                     __name__, 'It takes very long time to start the bot!!!') | ||||
|                     __name__, 'It takes far too long to prepare the database!!!') | ||||
|         except Exception as e:  # | ||||
|             self._logger.error(__name__, 'Database init time calculation failed', e) | ||||
|             return | ||||
|   | ||||
		Reference in New Issue
	
	Block a user