Skip to content

Commit

Permalink
1.3.0: Add missing type stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanC committed Jun 19, 2024
1 parent 09f3bd2 commit 9a7262d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
Empty file added loguru_discord/py.typed
Empty file.
12 changes: 5 additions & 7 deletions loguru_discord/sink.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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,
Expand Down Expand Up @@ -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.
Expand All @@ -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()

Expand Down Expand Up @@ -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",
)
Expand Down
25 changes: 25 additions & 0 deletions loguru_discord/sink.pyi
Original file line number Diff line number Diff line change
@@ -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: ...
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit 9a7262d

Please sign in to comment.