Right now my Django + Gunicorn app is printing only this info:

```
[03.10.2022 19:43:14] INFO [django.request:middleware] GET /analyse/v2/ping - 200

```

If request is authorized, I would like to show also user (username/email) behind the status code, something like:

```
[03.10.2022 19:43:14] INFO [django.request:middleware] GET /analyse/v2/ping - 200 - useremail@outlook.com

```

If the request is not authorized then write UNAUTHORIZED:

```
[03.10.2022 19:43:14] INFO [django.request:middleware] GET /analyse/v2/ping - 200 - UNAUTHORIZED

```

How can I achieve this with a combination of Django and Gunicorn?

Thank you

Solved by adding this part of code in settings:

```
def add_username(record):
    try:
        username = record.request.user.username
    except AttributeError:
        username = ""
    record.username = username
    return True

LOGGING = {
    "version": 1,
    "disable_existing_loggers": True,
    "root": {"level": "WARNING", "handlers": ["console"]},
    "formatters": {
        "verbose": {
            "format": "[%(asctime)s] %(levelname)s [%(name)s:%(module)s] [%(username)s] %(message)s",
            "datefmt": "%d.%m.%Y %H:%M:%S",
        },
        "simple": {"format": "%(levelname)s %(message)s"},
    },
    "filters": {
        "add_username": {
            "()": "django.utils.log.CallbackFilter",
            "callback": add_username,
        }
    },
    "handlers": {
        "console": {
            "level": "DEBUG",
            "class": "logging.StreamHandler",
            "formatter": "verbose",
            "filters": ["add_username"],
        },
    ...

```