Fix Logger.setLevel crash: use a logging.Filter to drop Image noise
Logger.setLevel('Image', 'CRITICAL') raised TypeError (takes 1 arg) and
crash-looped the player. Kivy routes all modules through the single 'kivy'
logger and the "[Image]" tag is just message-prefix formatting, so install a
logging.Filter on the 'kivy' logger that drops only
"Image: Error loading ..." records (benign: emitted by Video's inherited Image
loader) while keeping all other Kivy log records.
This commit is contained in:
+15
-2
@@ -63,8 +63,21 @@ from kivy.logger import Logger
|
|||||||
# Kivy's Video widget subclasses Image, so its inherited image loader always
|
# Kivy's Video widget subclasses Image, so its inherited image loader always
|
||||||
# runs first and logs a harmless "Image: Error loading <file.mp4>" for every
|
# runs first and logs a harmless "Image: Error loading <file.mp4>" for every
|
||||||
# video (the real decoding is done by the ffpyplayer CoreVideo provider).
|
# video (the real decoding is done by the ffpyplayer CoreVideo provider).
|
||||||
# Silence just that logger so genuine errors stay visible.
|
# Kivy routes every module through the single 'kivy' logger (the "[Image]" tag
|
||||||
Logger.setLevel('Image', 'CRITICAL')
|
# is just Kivy's message-prefix formatting), so drop only that one message and
|
||||||
|
# leave all other Kivy log records visible.
|
||||||
|
import logging
|
||||||
|
|
||||||
|
|
||||||
|
class _SuppressKivyImageNoise(logging.Filter):
|
||||||
|
def filter(self, record):
|
||||||
|
try:
|
||||||
|
return not record.getMessage().startswith('Image: Error loading')
|
||||||
|
except Exception:
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
logging.getLogger('kivy').addFilter(_SuppressKivyImageNoise())
|
||||||
|
|
||||||
# Try to import evdev for card reader support (after Logger is available)
|
# Try to import evdev for card reader support (after Logger is available)
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user