Skip to content

Commit 89e5b30

Browse files
Merge pull request #1 from puzzleYOU/impl
Initial setup with django http 404 logging filter
2 parents 965b6eb + a5ad309 commit 89e5b30

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

python_logging_filters/__init__.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import logging
2+
import re
3+
4+
5+
class DjangoHttp404LogFilter(logging.Filter):
6+
"""Suppresses Django's default 'Not Found: ...' log messages.
7+
8+
See the Django docs how to attach filters to logging handlers via
9+
the LOGGING setting.
10+
"""
11+
PATTERN = re.compile("^Not Found:")
12+
13+
def filter(self, record: logging.LogRecord) -> bool:
14+
return (
15+
self.PATTERN.fullmatch(record.msg) is not None
16+
and record.levelno == logging.WARNING
17+
and record.name.startswith("django")
18+
)

setup.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from setuptools import find_packages, setup
2+
3+
setup(
4+
name="python-logging-filters",
5+
version="0.1.0",
6+
description=(
7+
"Simple filters for standard python logging, e.g. for suppressing "
8+
"noisy 3rd party framework logging."
9+
),
10+
author="puzzleYOU GmbH",
11+
author_email="[email protected]",
12+
url="https://www.puzzleyou.de/",
13+
license="GPLv3",
14+
platforms=["any"],
15+
packages=find_packages(),
16+
install_requires=[],
17+
zip_safe=True,
18+
)

0 commit comments

Comments
 (0)