-
Notifications
You must be signed in to change notification settings - Fork 22
feat: add TRACE log level and patch_logging() #84
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -72,6 +72,12 @@ | |||||||||
| or an handler, this is used as an utility for debugging | ||||||||||
| purposes more that a real feature for production systems """ | ||||||||||
|
|
||||||||||
| TRACE = logging.DEBUG - 5 | ||||||||||
| """ The trace level used for extremely detailed and verbose | ||||||||||
| logging of protocol-level operations, this is meant to be | ||||||||||
| used for fine-grained debugging of low-level operations | ||||||||||
| like raw byte transfers and frame parsing """ | ||||||||||
|
|
||||||||||
| LEVELS = ("DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL") | ||||||||||
|
Comment on lines
+77
to
81
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
After introducing Useful? React with 👍 / 👎. |
||||||||||
| """ The sequence of levels from the least sever to the | ||||||||||
| most sever this sequence may be used to find all the | ||||||||||
|
|
@@ -292,6 +298,9 @@ def set_tid(self, value, *args, **kwargs): | |||||||||
|
|
||||||||||
|
|
||||||||||
| class DummyLogger(object): | ||||||||||
| def trace(self, object): | ||||||||||
| pass | ||||||||||
|
Comment on lines
+301
to
+302
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rename This triggers Ruff A002 and is easy to fix. ✏️ Proposed fix- def trace(self, object):
+ def trace(self, message):
pass📝 Committable suggestion
Suggested change
🧰 Tools🪛 Ruff (0.15.7)[error] 301-301: Function argument (A002) 🤖 Prompt for AI Agents |
||||||||||
|
|
||||||||||
| def debug(self, object): | ||||||||||
| pass | ||||||||||
|
|
||||||||||
|
|
@@ -355,11 +364,28 @@ def smtp_handler( | |||||||||
| ) | ||||||||||
|
|
||||||||||
|
|
||||||||||
| def patch_logging(): | ||||||||||
| if hasattr(logging, "_appier_patched"): | ||||||||||
| return | ||||||||||
|
|
||||||||||
| # patches the logging infra-structure adding the trace level | ||||||||||
| # support and the corresponding trace method to the logger | ||||||||||
| logging.addLevelName(TRACE, "TRACE") | ||||||||||
| logging.Logger.trace = _trace | ||||||||||
|
|
||||||||||
| logging._appier_patched = True | ||||||||||
|
|
||||||||||
|
|
||||||||||
| def in_signature(callable, name): | ||||||||||
| has_full = hasattr(inspect, "getfullargspec") | ||||||||||
| if has_full: | ||||||||||
| spec = inspect.getfullargspec(callable) | ||||||||||
| else: | ||||||||||
| spec = inspect.getargspec(callable) | ||||||||||
| args, _varargs, kwargs = spec[:3] | ||||||||||
| return (args and name in args) or (kwargs and "secure" in kwargs) | ||||||||||
| return bool((args and name in args) or (kwargs and "secure" in kwargs)) | ||||||||||
|
Comment on lines
379
to
+386
|
||||||||||
|
|
||||||||||
|
|
||||||||||
| def _trace(self, message, *args, **kwargs): | ||||||||||
| if self.isEnabledFor(TRACE): | ||||||||||
| self._log(TRACE, message, args, **kwargs) | ||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is_trace()should not treat level0as unset.if not self.levelreturnsFalseforlogging.NOTSET(0), but0should still satisfy trace-enabled checks.🔧 Proposed fix
🤖 Prompt for AI Agents