79641735

Date: 2025-05-28 07:48:53
Score: 0.5
Natty:
Report link

The issues are:

  1. Kivy's Logger is a separate logging system from Python's standard logging module.

  2. When you call Logger.addFilter(), you're adding a filter to Kivy's logger, not to Python's standard logging system.

  3. The logger = logging.getLogger('poopoo') creates a standard Python logger, which is completely independent from Kivy's Logger.

Issues with your code:

# Adds filter to Kivy Logger, not Python logger
Logger.addFilter(logging.Filter('poopoo'))

# NOT filtered (still shows DEBUG logs)
logger.debug('pylogger')  

Solution 1: Redirect Python logging to Kivy’s Logger.

from kivy.logger import LoggerHistory
import logging

class KivyHandler(logging.Handler):
    def emit(self, record):
        LoggerHistory.add_record(record)

root_logger = logging.getLogger()
root_logger.setLevel(logging.INFO)
root_logger.addHandler(KivyHandler())

logging.getLogger('poopoo').debug('This will be filtered by Kivy’s logger now')

Solution 2: you need to configure both systems separately.

import logging
from kivy.logger import Logger, LOG_LEVELS

if __name__ == '__main__':
    Logger.setLevel(LOG_LEVELS["info"])
    
    std_logger = logging.getLogger('poopoo')
    std_logger.setLevel(logging.INFO)
    
    for i in range(5):
        Logger.debug('kivy')
        std_logger.debug('pylogger')

Solution 3: If you want unified logging control, you can configure Python's root logger, which will affect most loggers (including third-party libraries):

import logging
from kivy.logger import Logger, LOG_LEVELS

if __name__ == '__main__':
    Logger.setLevel(LOG_LEVELS["info"])
    logging.basicConfig(level=logging.INFO)

    for i in range(5):
        Logger.debug('kivy')
        logging.getLogger('poopoo').debug('pylogger')
Reasons:
  • Blacklisted phrase (2): poop
  • Long answer (-1):
  • Has code block (-0.5):
Posted by: Subir Chowdhury