Message338092
In the logging Python library, one can completely disable logging (for all levels) for a particular logger either by setting its `disabled` attribute to `True`, or by adding to it a `lambda record: False` filter, or by adding to it a `logging.NullHandler()` handler (to avoid the `logging.lastResort` handler) and setting its `propagate` attribute to `False` (to avoid log record propagation to its parent loggers):
import logging
# 1st solution
logging.getLogger("foo").disabled = True
# 2nd solution
logging.getLogger("foo").addFilter(lambda record: False)
# 3rd solution
logging.getLogger("foo").addHandler(logging.NullHandler())
logging.getLogger("foo").propagate = False
One can obtain the same logging configuration for the 2nd and 3rd solutions with the `logging.config.dictConfig` function:
import logging.config
# 2nd solution
logging.config.dictConfig({
"version": 1,
"filters": {
"all": {
"()": lambda: (lambda record: False)
}
},
"loggers": {
"foo": {
"filters": ["all"]
}
}
})
# 3rd solution
logging.config.dictConfig({
"version": 1,
"handlers": {
"null": {
"class": "logging.NullHandler"
}
},
"loggers": {
"foo": {
"handlers": ["null"],
"propagate": False
}
}
})
However it is currently not possible for the 1st solution:
import logging.config
# 1st solution
logging.config.dictConfig({
"version": 1,
"loggers": {
"foo": {
"disabled": True
}
}
})
What do you think about adding this feature? I think it might be very convenient and improve consistency. |
|
Date |
User |
Action |
Args |
2019-03-16 18:35:29 | maggyero | set | recipients:
+ maggyero, vinay.sajip |
2019-03-16 18:35:29 | maggyero | set | messageid: <1552761329.43.0.180278602772.issue36318@roundup.psfhosted.org> |
2019-03-16 18:35:29 | maggyero | link | issue36318 messages |
2019-03-16 18:35:29 | maggyero | create | |
|