New GitHub issue #96158 from ccppoo:<br>
<hr>
<pre>
# Feature or enhancement
While I was writing `log_config.yaml` for my FastAPI app,
I found when using keyword `class` under name of the filter it didn't recognized from python
Two scripts below, in same the directory, could re-generate the behavior what I explained
```yaml
# loggerConfig.yaml
version: 1
disable_existing_loggers: False
formatters:
default:
datefmt: "%Y-%m-%d %H:%M:%S"
filters:
filterSample:
"()": __main__.filterSample
# class: __main__.filterSample <- un-comment this for re-generating
handlers:
default:
formatter: default
class: logging.StreamHandler
stream: ext://sys.stderr
filters:
- filterSample
loggers:
myLogger:
level: INFO
handlers:
- default
```
```python
# main.py
import logging.config
import logging
import yaml
class filterSample(logging.Filter):
def filter(self, record):
print("I am filter!")
return True
if __name__ == '__main__':
yamlConfig = './loggerConfig.yaml'
with open(yamlConfig, mode='r') as fp:
logging_config = yaml.load(fp, Loader=yaml.FullLoader)
logging.config.dictConfig(logging_config)
logger = logging.getLogger('myLogger')
logger.info("This is info logging")
```
This happens because it's designed as it was.
https://github.com/python/cpython/blob/d8c7a1174cc182668085b10aab4049f6a2794c2f/Lib/logging/config.py#L686-L695
No parsing for `class` keyword, only `'()'`
While other configs like `Handler`, `Formatter` searches for `class` if `'()`` does not exists
I see no reason why only `Filter` is not allowed to use `class`
# Pitch
It will feel harmonious if we could use `class` keyword for `Filter`s too!
I couldn't find all use cases and patterns how others use `logging.config.dictConfig`
But I assume that most of people won't use as custom keywords,
because `Handler` and `Formatter` uses `class` as reserved keyword
# Previous discussion
None
<!--
New features to Python should first be discussed elsewhere before creating issues on GitHub,
for example in the "ideas" category (https://discuss.python.org/c/ideas/6) of discuss.python.org,
or the python-ideas mailing list (https://mail.python.org/mailman3/lists/python-ideas.python.org/).
Use this space to post links to the places where you have already discussed this feature proposal:
-->
</pre>
<hr>
<a href="https://github.com/python/cpython/issues/96158">View on GitHub</a>
<p>Labels: type-feature</p>
<p>Assignee: </p>