New submission from Géry <[email protected]>:
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.
----------
components: Library (Lib)
messages: 338092
nosy: maggyero, vinay.sajip
priority: normal
severity: normal
status: open
title: Adding support for setting the "disabled" attribute of loggers from
logging.config.dictConfig
type: enhancement
versions: Python 3.7
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue36318>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com