Configure logging across multiple processes

I have a setup where the settings.py is shared by:

  • A django server running multiple processes with pyuwsgi
  • A celery app which sets the DJANGO_SETTINGS_MODULE to configure celery app
  • A handful of periodic & manually run jobs which invoke manage.py

The LOGGING configuration is then shared by each of these, which includes the logfile name. This seems to me to result in the bad situation described in the python logging-cookbook where multiple unrelated processes are logging to the same file.

How should one configure separate files for each of these processes? Ideally I could see something as simple as naming the file differently based upon each “main”, but I can’t seem to figure a clean way to detect which processes is importing the settings.py.

Welcome @rhoban13 !

I would check sys.argv. I believe you should be able to identify what you need from it.

That seems to work quite well. Thank you!

For future ref, this article on configuring logging does a way better job than I could of at least clarifying some of my concerns with the default logging setup running via uwsgi.