Skip to content

Commit

Permalink
SensitiveFormatter
Browse files Browse the repository at this point in the history
  • Loading branch information
Archmonger committed Aug 25, 2022
1 parent e79c171 commit 55f3849
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
6 changes: 3 additions & 3 deletions conreq/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,11 @@
"disable_existing_loggers": False,
"formatters": {
"default": {
"class": "conreq.utils.logging.SensitiveFormatter",
"format": "%(asctime)s %(levelname)s %(name)s: %(message)s",
},
"minimal": {
"class": "conreq.utils.logging.SensitiveFormatter",
"format": "%(levelname)s %(name)s: %(message)s",
},
},
Expand Down Expand Up @@ -440,9 +442,7 @@
if not get_safe_mode():
user_apps = find_apps()
INSTALLED_APPS += user_apps
_logger.info(
"Starting Conreq with the following apps:\n+ " + "\n+ ".join(user_apps)
)
_logger.info("Booting with the following apps:\n+ " + "\n+ ".join(user_apps))

# Run startup.py
packages = find_packages()
Expand Down
15 changes: 15 additions & 0 deletions conreq/utils/logging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import logging
import re


class SensitiveFormatter(logging.Formatter):
"""Formatter that removes sensitive information in URLs."""

@staticmethod
def _filter(s):
# Removes query parameters from the URL
return re.sub(r"( /)(\S+)([?])(\S+?[=]\S+)", r"\1\2", s)

def format(self, record):
original = logging.Formatter.format(self, record)
return self._filter(original)

0 comments on commit 55f3849

Please sign in to comment.