Skip to content

Commit

Permalink
Improve logging configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbru committed Oct 24, 2024
1 parent 47b914f commit c7306de
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
1 change: 1 addition & 0 deletions {{cookiecutter.project_slug}}/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ skip = node_modules,migrations
[tool:pytest]
DJANGO_SETTINGS_MODULE = {{cookiecutter.project_slug}}.config.settings.test
python_files = test*.py tests.py tests/*.py
log_level = INFO
norecursedirs = node_modules .git
addopts = --cov-report=term --cov={{cookiecutter.project_slug}} --no-cov-on-fail
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,43 @@
# LOGGING #
###########

# Django first applies its default configuration (`django.utils.log.DEFAULT_LOGGING`),
# then it applies this one (it calls logging.config.dictConfig twice).
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"handlers": {"console": {"level": "INFO", "class": "logging.StreamHandler"}},
"loggers": {"": {"handlers": ["console"], "level": "ERROR", "propagate": True}},
# This config will not affect existing handlers/filters/formatters that were
# declared with the same name, and loggers of this config can only reference these
# handlers/filters/formatters.
"formatters": {
"simple": {"format": "{name}:{levelname[0]} {message}", "style": "{"},
},
"handlers": {
"console": {
"level": "INFO",
"formatter": "simple",
"class": "logging.StreamHandler",
},
},
# If loggers with the same name already exist, dictConfig will only apply explicitly
# specified settings to the existing loggers, except for "handlers" and "filters"
# that are always reset (see `logging.config.DictConfigurator.configure_logger`).
#
# On the other hand, for child loggers (e.g. "django.server" when overriding "django"),
# dictConfig will reset "handlers", "level" and "propagate" to their default values,
# but not "filters" (see `logging.config._handle_existing_loggers`).
"loggers": {
"": {
"handlers": ["console"],
"level": "NOTSET",
},
"django": {
# Delegate to root logger
"handlers": (),
"level": "NOTSET",
"propagate": True,
},
},
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@

INSTALLED_APPS += ("debug_toolbar", "django_extensions") # noqa

LOGGING = {}
STATICFILES_STORAGE = "django.contrib.staticfiles.storage.StaticFilesStorage"
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,3 @@

# use basic password hashing for tests for better performance
PASSWORD_HASHERS = ["django.contrib.auth.hashers.MD5PasswordHasher"]

# Disable logging messages
LOGGING = {}

0 comments on commit c7306de

Please sign in to comment.