0

I set up a python logger and I want to be able to add a filter I created to just the logging.ERROR level of the log.

I've tried this:

class MyFilter(object):
  def __init__(self, level):
    self.__level = level

  def filter(self, logRecord):
    return logRecord.levelno <= self.__level

logger = logging.getLogger()
handler = logging.StreamHandler()
formatter = logging.Formatter(
        '%(levelname)-8s %(msg)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
logger.setLevel(logging.INFO)

logger.addFilter(MyFilter(logging.ERROR))

When I try this, I get an error: TypeError: object of type 'int' has no len()

How do you add filters to specific logging levels?

2

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.