On this page
  1. logging.Filter
  2. Import
  3. Signature & Overview
  4. Methods & Attributes
  5. Usage
  6. Gotchas
  7. REPL Inspect

logging.Filter

Prev: logging.FileHandler | Up: logging | Next: logging.Formatter
Rel: logging.addLevelName, logging.basicConfig, logging.BufferingFormatter, logging.captureWarnings
Ref: docs.python.org — logging.Filter
Tags: #public #python3 #stdlib #logging


Import

import logging
from logging import Filter

Signature & Overview

logging.Filter(name='')

Filter instances are used to perform arbitrary filtering of LogRecords.

Methods & Attributes

Usage

import logging

class DropHealthcheck(logging.Filter):
    def filter(self, record: logging.LogRecord) -> bool:
        return "/health" not in record.getMessage()

f = DropHealthcheck()
r1 = logging.LogRecord("web", logging.INFO, "", 1, "GET /health", (), None)
r2 = logging.LogRecord("web", logging.INFO, "", 1, "GET /api", (), None)
assert f.filter(r1) is False and f.filter(r2) is True

Gotchas

REPL Inspect

from logging import Filter
help(Filter)

Linked from

Related notes