Only pass libav logger messages when stream logger is set to debug (#57616)

This commit is contained in:
uvjustin 2021-10-14 23:43:00 +08:00 committed by GitHub
parent b28062789f
commit ce186c5935
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -105,11 +105,34 @@ CONFIG_SCHEMA = vol.Schema(
)
def filter_libav_logging() -> None:
"""Filter libav logging to only log when the stream logger is at DEBUG."""
stream_debug_enabled = logging.getLogger(__name__).isEnabledFor(logging.DEBUG)
def libav_filter(record: logging.LogRecord) -> bool:
return stream_debug_enabled
for logging_namespace in (
"libav.mp4",
"libav.h264",
"libav.hevc",
"libav.rtsp",
"libav.tcp",
"libav.tls",
"libav.NULL",
):
logging.getLogger(logging_namespace).addFilter(libav_filter)
# Set log level to error for libav.mp4
logging.getLogger("libav.mp4").setLevel(logging.ERROR)
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up stream."""
# Set log level to error for libav
logging.getLogger("libav").setLevel(logging.ERROR)
logging.getLogger("libav.mp4").setLevel(logging.ERROR)
# Drop libav log messages if stream logging is above DEBUG
filter_libav_logging()
# Keep import here so that we can import stream integration without installing reqs
# pylint: disable=import-outside-toplevel