Support custom logging levels in logger stdlib package
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 516
- PR merge metrics
- No merged PRs in 30d
Description
### Describe the Bug
Custom log levels are configured via methods that are dynamically added to the class, which causes some false positives for us
We should at least narrow the object to contain that attribute, but if the logger is configured at the top level it wouldn't apply to nested scopes unless we do https://github.com/facebook/pyrefly/issues/40, AND if the logger is configured in some factory function then we're out of luck
```
import logging
# Define a custom TRACE level (value 5, lower than DEBUG's 10)
TRACE_LEVEL_NUM = 5
logging.addLevelName(TRACE_LEVEL_NUM, "TRACE")
def trace(self, message, *args, **kws):
if self.isEnabledFor(TRACE_LEVEL_NUM):
self._log(TRACE_LEVEL_NUM, message, args, **kws)
# Add the trace method to the standard Logger class
logging.Logger.trace = trace
# --- Usage Example ---
# Configure the root logger to handle the TRACE level
logging.basicConfig(level=TRACE_LEVEL_NUM)
logger = logging.getLogger(__name__)
logger.trace("A custom trace message with value %s", 5) # false positive error here
logger.debug("A standard debug message")
```
from https://youtrack.jetbrains.com/issue/PY-86719/Pyrefly-is-way-too-overzealous
### Sandbox Link
https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeSIEAtsbgE4AuABFLgOZsTpsA66fAYiYARGJHQwmqJgGMArnAa4qTACoAlAIIBhAKIsYANxhQmACkOoocyQFYANC1wB3GHSYMAFhhG6AQgCqAOIA5HBMAIwADACUfBo6ugD6ADK6AGq6KUkAcgEAskwAvEy2fKwcXGyEqJiYKUYmOahUMGYJeqkZWbkFjjwgHboDcfxYYh50qDJtcCZgjq1waGwwjgBUqHRscBvrANbOcDGIfEznTBBgTHNQYIQQcLroqNiwmABi9O1anWmZ2Ty%2BROZwuYNu9ySFR%2BiS6AN6%2BUW8BWayk212THWByOo0ETE0dQ8nkkDCmMyYrS8uEwHlwRMkigwmC2NJS7FW7hkUFQy3K7KqhDZHDchFJ00kJTFMz4eIAtPKmAEUUxdPgWsRYEx5bK8dpcOhIGw5HQScSmHRcLhmBUObSmN4sJqvJIhgZjFA%2BZVuIRsDyIDI9QaIGwzLB3UUhnCekCYkxPbaSjaBasGEKOWYkkkXq1M7j0DaRVK2gNNLIFEoVEWKcjUKsmM4IF4mJZrJIAKRwAaOWyjAt0QiYGDYOQhks3BhMllMQfDtjV5a1mAjED2EBkE1gKCkUXKKAUIQABVIG63NyZeHwsn1huNqAYEH1hDxAGUYJJPAwGMQ4IgAPS-9cxC3Qh6DYX8YHQX9MFwGQ4F-GRr2DW9731X8mDAegpEsaBXk1BCgyNKYUPQJhcGIYi4CfdAyCpdBZWMOg4AfEiSgGABmQgIgAJgGPgQAAX1XaZ72MD5oBgCg0CwC8SHIfigA
### (Only applicable for extension issues) IDE Information
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.