How do I make django's default logs go to a file?

No matter what I try, this doesn’t seem to work. log json, code-based setup, none of them work.

I’m talking about default logs, not the logs I make by myself btw. Those go to a file perfectly fine, but django’s default logs seem unfazed by my configuration and I do not know why.

Specifically, what logs are you talking about?

Also, please post the LOGGING settings you are using.

These logs:


These are my logging settings:

{
    "version": 1,
    "disable_existing_loggers": False,
    "filters": {
        "log_ctx": {
            "()": "core.util.logging_util.__LogContextFilter",
        },
    },
    "formatters": {
        "json": {
            "()": "pythonjsonlogger.json.JsonFormatter",
            "fmt": "%(asctime)s %(name)s %(levelname)s %(message)s %(lineno)s",
        },
        "colored": {
            "()": "core.util.logging_util.__ColoredStdoutFormatter",
        },
    },
    "handlers": {
        "file": {
            "level": "DEBUG",
            "class": "logging.FileHandler",
            "filename": "logs/main.log",
            "formatter": "json",
            "filters": ["log_ctx"],
        },
        "console": {
            "level": "INFO",
            "class": "logging.StreamHandler",
            "formatter": "colored",
            "filters": ["log_ctx"],
        },
    },
    "loggers": {
        "": {
            "handlers": ["file", "console"],
            "level": "DEBUG",
            "propagate": True
        },
        "django": {
            "handlers": ["file", "console"],
            "level": "INFO",
            "propagate": True
        }
    }
}

These settings work for all of my logging except for django’s builtin stuff. Is there a way to make django’s builtin stuff respect these settings too?

That’s because those logs are not part of Django and have nothing directly to do with Django. Those are the logs from your asgi container, Uvicorn.

See the Uvicorn docs for logging for information to capture those logs.