Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] #3125: Remove JSON formatting from Non-Error logs - [MS] #3298

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions src/registrar/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,14 +486,6 @@ def format(self, record):
log_entry = {"server_time": record.server_time, "level": record.levelname, "message": formatted_record}
return json.dumps(log_entry)


# default to json formatted logs
server_formatter, console_formatter = "json.server", "json"

# don't use json format locally, it makes logs hard to read in console
if "localhost" in env_base_url:
server_formatter, console_formatter = "django.server", "verbose"

LOGGING = {
"version": 1,
# Don't import Django's existing loggers
Expand Down Expand Up @@ -526,17 +518,34 @@ def format(self, record):
"console": {
"level": env_log_level,
"class": "logging.StreamHandler",
"formatter": console_formatter,
"formatter": "verbose",
# "filters": ["below_error"],
},
"django.server": {
"level": "INFO",
"class": "logging.StreamHandler",
"formatter": server_formatter,
"formatter": "django.server",
},
# log all messages at ERROR level or higher using json formatter
# We do this because error logs often comprise many lines,
# and json formatting makes them easier to parse.
"json": {
"level": "ERROR",
"class": "logging.StreamHandler",
"formatter": "json",
},
# No file logger is configured,
# because containerized apps
# do not log to the file system.
},
# filters are used to filter messages based on a callback function
"filters": {
# filter for messages below ERROR level
"below_error": {
"()": "django.utils.log.CallbackFilter",
"callback": lambda record: record.levelno < logging.ERROR,
}
},
# define loggers: these are "sinks" into which
# messages are sent for processing
"loggers": {
Expand Down
Loading