diff --git a/loguru_discord/py.typed b/loguru_discord/py.typed new file mode 100644 index 0000000..e69de29 diff --git a/loguru_discord/sink.py b/loguru_discord/sink.py index 26c9c3c..8a4ae0e 100644 --- a/loguru_discord/sink.py +++ b/loguru_discord/sink.py @@ -1,6 +1,6 @@ import logging from logging import Handler, LogRecord -from typing import Any, Self +from typing import Any from discord_webhook import DiscordEmbed, DiscordWebhook @@ -9,7 +9,7 @@ class DiscordSink(Handler): """Logging handler that enables sending logs to a Discord Webhook.""" def __init__( - self: Self, + self, webhookUrl: str, *, username: str | None = None, @@ -52,7 +52,7 @@ def __init__( rate_limit_retry=True, ) - def emit(self: Self, record: LogRecord) -> None: + def emit(self, record: LogRecord) -> None: """ Override the emit method of the logging handler, sends the log to a Discord Webhook. @@ -71,12 +71,10 @@ def emit(self: Self, record: LogRecord) -> None: maxEmbedDesc: int = 4083 maxEmbedFooter: int = 2040 - try: + if record.exc_info: # Get Exception type from exc_info tuple if record.exc_info[0] in self.suppress: return - except Exception: - pass message: str = record.getMessage() @@ -108,7 +106,7 @@ def emit(self: Self, record: LogRecord) -> None: pass embed.set_title(record.levelname[:maxEmbedTitle]) - embed.set_footer( + embed.set_footer( # type: ignore text=f"{record.filename[:maxEmbedFooter]}:{record.lineno:,}", icon_url="https://i.imgur.com/7xeGMSf.png", ) diff --git a/loguru_discord/sink.pyi b/loguru_discord/sink.pyi new file mode 100644 index 0000000..c21d27b --- /dev/null +++ b/loguru_discord/sink.pyi @@ -0,0 +1,25 @@ +from logging import Handler, LogRecord +from typing import Any + +from discord_webhook import DiscordWebhook + +class DiscordSink(Handler): + webhookUrl: str + username: str | None + avatarUrl: str | None + embed: bool + truncate: bool + suppress: list[Any] + webhook: DiscordWebhook + + def __init__( + self, + webhookUrl: str, + *, + username: str | None = None, + avatarUrl: str | None = None, + embed: bool = False, + truncate: bool = False, + suppress: list[Any] = [], + ) -> None: ... + def emit(self, record: LogRecord) -> None: ... diff --git a/pyproject.toml b/pyproject.toml index 7f37c21..5f63559 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "loguru-discord" -version = "1.2.2" +version = "1.3.0" description = "Lightweight, easy-to-use Discord sink for Loguru." authors = ["EthanC <16727756+EthanC@users.noreply.github.com>"] license = "MIT"