Improve default LOGGING settings

By default, Django doesn’t enable logging for the project module it creates with startproject and logging is essentially turned off if DEBUG=False. As a new user, I would expect Django to do the right thing for me and provide sane defaults for both development and production. The current settings don’t do that.

In the docs, I have to go to “an example of a fairly complex logging setup” to see how one might output logging statements from their project.

Python logging is confusing, even for experienced developers. Could Django do a better job with it’s default logging settings?

I would love to see:

  • console logging always enabled
  • root logger set to log anything at warning or above
  • django and the project module set to log anything at info or above (maybe drop to debug when DEBUG=True)

This could be done by adding LOGGING to the startproject settings template, so it wouldn’t change functionality on existing projects.

What do you think?

11 Likes

Yes, I’d be +1 here. I basically end up copying in a standard setup for each project, and it’s a frequent pain point for folks getting the hang of Python logging.

Setting up the root logger with a console handler is going to be a massive help to a lot of people.

Having a logging setting to edit in the template is going to be a lot easier on-ramp than having to discover how to write one from scratch.

:+1:

The default snippet I copy and add paste has the debug DB logger there but commented, because it’s pretty noisy. (But also hard to recall just what you need.)

2 Likes

Yeah, I think that even to add the default logging to the auto-generated settings.py would be beneficial

Yes…Logging and having an appropriate log management system are some of the most imperative points for every software project. One of the recommended features is to have a separate database such as Elastic (a NoSQL database) since it is faster in retrieving and accessing logs. There are also several pieces of documentation that explain the integration between ELK and Django and provide configurations in settings.

If had my own share of experiences with logging and my takeaway is, that there is a lot that’s documented. And that the documentation does not explain everything, leaving the developer with half-baked knowledge that can’t be applied to a real-world scenario. Somewhere in the Django docs it is briefly mentioned that logging builds on the Python logging facility. If you happen to not notice or misinterpret that, and you don’t read through the Python docs as well, nothing will make sense. This was my experience: Logging does not work as expected

I would say, not only improve the default logging settings, but explain them better as well.