docs: compress prose/module docstrings, em-dash->hyphen (de-bloat wave 1)
Signed-off-by: disqualifier <dev@disqualifier.me>
This commit is contained in:
@@ -10,18 +10,18 @@ live from `bot.settings` so it can change at runtime via a command.
|
|||||||
`requirements.txt`:
|
`requirements.txt`:
|
||||||
|
|
||||||
```
|
```
|
||||||
dpy_logger @ git+ssh://git@git.rethinkstudios.io/rethink-public/dpy_logger.git@v0.1.6
|
dpy_logger @ git+ssh://git@git.rethinkstudios.io/rethink-public/dpy_logger.git@v0.1.7
|
||||||
```
|
```
|
||||||
|
|
||||||
Direct:
|
Direct:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pip install "dpy_logger @ git+ssh://git@git.rethinkstudios.io/rethink-public/dpy_logger.git@v0.1.6"
|
pip install "dpy_logger @ git+ssh://git@git.rethinkstudios.io/rethink-public/dpy_logger.git@v0.1.7"
|
||||||
```
|
```
|
||||||
|
|
||||||
Requires `discord.py` (pulled transitively).
|
Requires `discord.py` (pulled transitively).
|
||||||
|
|
||||||
Drop the `@v0.1.6` suffix from the line above to install the latest unpinned.
|
Drop the `@v0.1.7` suffix from the line above to install the latest unpinned.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "dpy_logger"
|
name = "dpy_logger"
|
||||||
version = "0.1.6"
|
version = "0.1.7"
|
||||||
description = "Leveled Discord channel logger for discord.py — config-free, injectable, installable."
|
description = "Leveled Discord channel logger for discord.py — config-free, injectable, installable."
|
||||||
requires-python = ">=3.10"
|
requires-python = ">=3.10"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
|||||||
@@ -19,31 +19,22 @@ read live from bot.settings at call time (no restart needed).
|
|||||||
await bot.log.initialize() # resolves ids -> objects
|
await bot.log.initialize() # resolves ids -> objects
|
||||||
await bot.log.success("user promoted", action="promote", actor=ctx.author)
|
await bot.log.success("user promoted", action="promote", actor=ctx.author)
|
||||||
|
|
||||||
levels: debug, info, success, fail (alias failure), task, critical.
|
levels: debug, info, success, fail (alias failure), task, critical. a per-call
|
||||||
|
guild= argument routes to that guild's bot.settings[guild.id]['channels']['logs']
|
||||||
|
instead of the construction channel. pass embed_builder=fn(logger, level, action,
|
||||||
|
actor, details) -> discord.Embed to restyle without subclassing, or override
|
||||||
|
build_embed in a subclass for complex cases. no feed/announcement method by
|
||||||
|
design; subclass and reuse _resolve for project-specific log types.
|
||||||
|
|
||||||
dynamic routing: a per-call guild= argument logs to that guild's configured
|
dual sink: every call also mirrors to the stdlib logger (getLogger(__name__))
|
||||||
channel via bot.settings[guild.id]['channels']['logs']; omit it to use the
|
before the discord send, so the record survives even if discord fails. set
|
||||||
construction channel.
|
log_to_file=False at construction, or per call, to disable.
|
||||||
|
|
||||||
custom embeds: pass embed_builder=fn(logger, level, action, actor, details)
|
|
||||||
-> discord.Embed to restyle without subclassing; every level routes through
|
|
||||||
it. for complex cases override build_embed in a subclass instead.
|
|
||||||
|
|
||||||
dual sink: every call also mirrors to the stdlib logger (getLogger(__name__));
|
|
||||||
the stdlib emit happens before the discord send, so the record survives even
|
|
||||||
if discord fails. set log_to_file=False at construction, or per call, to
|
|
||||||
disable.
|
|
||||||
|
|
||||||
extending: no feed/announcement method by design; subclass and reuse
|
|
||||||
_resolve for project-specific log types.
|
|
||||||
|
|
||||||
errors: setup raises, sends swallow. resolution failures (unresolvable
|
errors: setup raises, sends swallow. resolution failures (unresolvable
|
||||||
guild/channel, bad config, a non-text channel, an invalid timezone) raise
|
guild/channel, bad config, a non-text channel, an invalid timezone) raise
|
||||||
ValueError from `initialize()`. underlying discord exceptions (NotFound/
|
ValueError from `initialize()`, with underlying discord exceptions normalized
|
||||||
Forbidden/HTTPException/InvalidData and other ClientException subclasses)
|
to it. per-call send failures never propagate - they fall back to the stdlib
|
||||||
are normalized to that same ValueError. on a per-call send, resolution and
|
logger so a transient discord failure never breaks the caller's command.
|
||||||
send failures never propagate — they fall back to the stdlib logger so a
|
|
||||||
transient discord failure never breaks the caller's command.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
@@ -114,14 +105,10 @@ class DPYLogger:
|
|||||||
if not self.guild:
|
if not self.guild:
|
||||||
raise ValueError(f"[dpy_logger] cannot resolve channel {self.channel} without a guild")
|
raise ValueError(f"[dpy_logger] cannot resolve channel {self.channel} without a guild")
|
||||||
self.channel = await self._get_channel(self.guild)
|
self.channel = await self._get_channel(self.guild)
|
||||||
# a channel with no guild would otherwise blackout every send silently; derive
|
|
||||||
# the guild from it, or fail loud here rather than later
|
|
||||||
if self.guild is None and isinstance(self.channel, discord.TextChannel):
|
if self.guild is None and isinstance(self.channel, discord.TextChannel):
|
||||||
self.guild = self.channel.guild
|
self.guild = self.channel.guild
|
||||||
if self.guild is None and self.channel is not None:
|
if self.guild is None and self.channel is not None:
|
||||||
raise ValueError("[dpy_logger] channel provided without a resolvable guild")
|
raise ValueError("[dpy_logger] channel provided without a resolvable guild")
|
||||||
# a wrong-type channel object (Thread/VoiceChannel/ForumChannel) would also pass
|
|
||||||
# silently and misroute/blackhole later; fail loud here instead
|
|
||||||
if self.channel is not None and not isinstance(self.channel, (discord.TextChannel, int)):
|
if self.channel is not None and not isinstance(self.channel, (discord.TextChannel, int)):
|
||||||
raise ValueError(f"[dpy_logger] channel {self.channel!r} is not a text channel")
|
raise ValueError(f"[dpy_logger] channel {self.channel!r} is not a text channel")
|
||||||
|
|
||||||
@@ -183,7 +170,6 @@ class DPYLogger:
|
|||||||
if self._embed_builder is not None:
|
if self._embed_builder is not None:
|
||||||
return self._embed_builder(self, level, action, actor, details)
|
return self._embed_builder(self, level, action, actor, details)
|
||||||
em = discord.Embed(color=self.colors[level])
|
em = discord.Embed(color=self.colors[level])
|
||||||
# is-not-None keeps falsy-but-valid values (0, False) rendering
|
|
||||||
if action is not None and str(action) != "":
|
if action is not None and str(action) != "":
|
||||||
em.add_field(name="Action", value=f"`{action}`", inline=True)
|
em.add_field(name="Action", value=f"`{action}`", inline=True)
|
||||||
if actor is not None and str(actor) != "":
|
if actor is not None and str(actor) != "":
|
||||||
@@ -209,12 +195,7 @@ class DPYLogger:
|
|||||||
|
|
||||||
async def _send(self, level, log_msg, action=None, actor=None, guild=None,
|
async def _send(self, level, log_msg, action=None, actor=None, guild=None,
|
||||||
log_to_file=None, content=None):
|
log_to_file=None, content=None):
|
||||||
"""resolve channel and dispatch a leveled embed; mirror to stdlib unless opted out
|
"""resolve channel and dispatch a leveled embed; mirror to stdlib unless opted out"""
|
||||||
|
|
||||||
stdlib emit happens first so the record survives a failed discord send, which
|
|
||||||
falls back to stdlib rather than propagating. `content` carries the critical-level
|
|
||||||
ping/@here text (None for other levels), so every level shares this one contract.
|
|
||||||
"""
|
|
||||||
if self.log_to_file if log_to_file is None else log_to_file:
|
if self.log_to_file if log_to_file is None else log_to_file:
|
||||||
self._emit_stdlib(level, action, actor, log_msg)
|
self._emit_stdlib(level, action, actor, log_msg)
|
||||||
try:
|
try:
|
||||||
@@ -248,7 +229,7 @@ class DPYLogger:
|
|||||||
async def task(self, log, action=None, actor=None, guild=None, log_to_file=None):
|
async def task(self, log, action=None, actor=None, guild=None, log_to_file=None):
|
||||||
"""log a task-level message with SYSTEM/TASK as the actor
|
"""log a task-level message with SYSTEM/TASK as the actor
|
||||||
|
|
||||||
actor is accepted for caller compatibility and ignored — task actions are
|
actor is accepted for caller compatibility and ignored - task actions are
|
||||||
always attributed to SYSTEM/TASK regardless of the caller-supplied actor
|
always attributed to SYSTEM/TASK regardless of the caller-supplied actor
|
||||||
"""
|
"""
|
||||||
return await self._send("task", log, action, "SYSTEM/TASK", guild, log_to_file)
|
return await self._send("task", log, action, "SYSTEM/TASK", guild, log_to_file)
|
||||||
|
|||||||
Reference in New Issue
Block a user