aboutsummaryrefslogtreecommitdiffstats
path: root/bot/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'bot/__init__.py')
-rw-r--r--bot/__init__.py69
1 files changed, 22 insertions, 47 deletions
diff --git a/bot/__init__.py b/bot/__init__.py
index db576cb2..3136c863 100644
--- a/bot/__init__.py
+++ b/bot/__init__.py
@@ -7,72 +7,47 @@ except ModuleNotFoundError:
import asyncio
import logging
-import logging.handlers
import os
from functools import partial, partialmethod
-from pathlib import Path
import arrow
+import sentry_sdk
from discord.ext import commands
+from sentry_sdk.integrations.logging import LoggingIntegration
+from sentry_sdk.integrations.redis import RedisIntegration
-from bot import monkey_patches
-from bot.constants import Client
+from bot import log, monkey_patches
+sentry_logging = LoggingIntegration(
+ level=logging.DEBUG,
+ event_level=logging.WARNING
+)
-# Configure the "TRACE" logging level (e.g. "log.trace(message)")
-logging.TRACE = 5
-logging.addLevelName(logging.TRACE, "TRACE")
+sentry_sdk.init(
+ dsn=os.environ.get("BOT_SENTRY_DSN"),
+ integrations=[
+ sentry_logging,
+ RedisIntegration()
+ ],
+ release=f"sir-lancebot@{os.environ.get('GIT_SHA', 'foobar')}"
+)
-logging.Logger.trace = monkey_patches.trace_log
+log.setup()
# Set timestamp of when execution started (approximately)
start_time = arrow.utcnow()
-# Set up file logging
-log_dir = Path("bot/log")
-log_file = log_dir / "hackbot.log"
-os.makedirs(log_dir, exist_ok=True)
-
-# File handler rotates logs every 5 MB
-file_handler = logging.handlers.RotatingFileHandler(
- log_file, maxBytes=5 * (2**20), backupCount=10, encoding="utf-8",
-)
-file_handler.setLevel(logging.TRACE if Client.debug else logging.DEBUG)
-
-# Console handler prints to terminal
-console_handler = logging.StreamHandler()
-level = logging.TRACE if Client.debug else logging.INFO
-console_handler.setLevel(level)
-
-# Remove old loggers, if any
-root = logging.getLogger()
-if root.handlers:
- for handler in root.handlers:
- root.removeHandler(handler)
-
-# Silence irrelevant loggers
-logging.getLogger("discord").setLevel(logging.ERROR)
-logging.getLogger("websockets").setLevel(logging.ERROR)
-logging.getLogger("PIL").setLevel(logging.ERROR)
-logging.getLogger("matplotlib").setLevel(logging.ERROR)
-logging.getLogger("async_rediscache").setLevel(logging.WARNING)
-
-# Setup new logging configuration
-logging.basicConfig(
- format="%(asctime)s - %(name)s %(levelname)s: %(message)s",
- datefmt="%D %H:%M:%S",
- level=logging.TRACE if Client.debug else logging.DEBUG,
- handlers=[console_handler, file_handler],
-)
-logging.getLogger().info("Logging initialization complete")
-
-
# On Windows, the selector event loop is required for aiodns.
if os.name == "nt":
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
monkey_patches.patch_typing()
+# This patches any convertors that use PartialMessage, but not the PartialMessageConverter itself
+# as library objects are made by this mapping.
+# https://github.com/Rapptz/discord.py/blob/1a4e73d59932cdbe7bf2c281f25e32529fc7ae1f/discord/ext/commands/converter.py#L984-L1004
+commands.converter.PartialMessageConverter = monkey_patches.FixedPartialMessageConverter
+
# Monkey-patch discord.py decorators to use the both the Command and Group subclasses which supports root aliases.
# Must be patched before any cogs are added.
commands.command = partial(commands.command, cls=monkey_patches.Command)