Loguru as Django Logging Middleware

I want to use Loguru (GitHub - Delgan/loguru: Python logging made (stupidly) simple) as a logging package for Django.
I already found out that I can use Loguru as middleware in Django: Middleware | Django documentation | Django
I found this useful tutorial to get an idea how that integration could work: GitHub - Delgan/loguru: Python logging made (stupidly) simple


  • I want to use classes instead of functions
  • The tutorial only uses the info logging, but all other levels (debug , warning , …) are missing
  • Some HTTP 404 (file not found) messages were not covered even if I configure all levels manually in that function. I’m not sure if that happened, because underlaying packages like the python webserver throw that error code? Some 404 worked, some not


  • I would like to use that middleware as an package that can be added to Django or replaced by another logging package (or even don’t use that package at all). That means that I want to use the built-in logging function in my app (models, …), so these apps don’t depend on this specific package and its functions, but when adding the middleware the logging will be handled by that package.

Next steps afterwards:

  • I want to provide a Loguru model in Django, so I can add the logging messages into the database, so i can use these in my frontend
  • I already use Celery and want Celery to depend on the Django logging settings and environment

Has anyone on idea how to continue? I’m stuck in the mud! :smiley:

Why middleware?

I’d guess you should just configure logging (LOGGING setting) for Django and define your loggers, handlers, etc.

A handler then can be written to forward log messages to a database.