Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more logic to the logging util #195

Merged
merged 2 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ Changelog
=========


- :release:`10.3.0 <19th September 2023>`
- :feature:`195` Add `log_format` to `pydis_core.utils.logging` to allow for standardised logging across all services using pydis_core.
- :feature:`195` Set `discord`, `websockets`, `chardet` & `async_rediscache` loggers to warning level and `asyncio` to info level by default.


- :release:`10.2.0 <28th August 2023>`
- :support:`192` Bump Discord.py to :literal-url:`2.3.2 <https://github.com/Rapptz/discord.py/releases/tag/v2.3.2>`.

Expand Down
13 changes: 13 additions & 0 deletions pydis_core/utils/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
LoggerClass = logging.getLoggerClass()

TRACE_LEVEL = 5
log_format = logging.Formatter("%(asctime)s | %(levelname)s | %(name)s | %(message)s")
"""
A :obj:`logging.Formatter` that can be used to standardise logging across all projects using pydis_core.

:meta hide-value:
ChrisLovering marked this conversation as resolved.
Show resolved Hide resolved
"""


class CustomLogger(LoggerClass):
Expand Down Expand Up @@ -49,3 +55,10 @@ def get_logger(name: str | None = None) -> CustomLogger:
logging.TRACE = TRACE_LEVEL
logging.setLoggerClass(CustomLogger)
logging.addLevelName(TRACE_LEVEL, "TRACE")

get_logger("discord").setLevel(logging.WARNING)
get_logger("websockets").setLevel(logging.WARNING)
get_logger("chardet").setLevel(logging.WARNING)
get_logger("async_rediscache").setLevel(logging.WARNING)
# Set back to the default of INFO even if asyncio's debug mode is enabled.
get_logger("asyncio").setLevel(logging.INFO)
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 = "pydis_core"
version = "10.2.0"
version = "10.3.0"
description = "PyDis core provides core functionality and utility to the bots of the Python Discord community."
authors = ["Python Discord <[email protected]>"]
license = "MIT"
Expand Down