zerosleeps

Since 2010

Log database queries in Django

While I’m on the topic of logging in Django, it makes me sad and a little bit grumpy that when you take Django out of the box, it doesn’t default to showing you what it’s doing with your database.

Here’s a LOGGING configuration that takes care of that, and sends everything from django.db.backends to a file in the project’s root directory during development:

LOGGING = {
    "version": 1,
    "disable_existing_loggers": False,
    "handlers": {
        "db_backends_file": {
            "class": "logging.FileHandler",
            "filename": BASE_DIR / "db_backends.log"
        }
    },
    "loggers": {
        "django.db.backends": {
            "level": "DEBUG",
            "handlers": ["db_backends_file"]
        }
    }
}

It’s important to note that django.db.backends only generates output when the DEBUG setting is True.

Log HTTP 5xx responses in Django

By default, in a production environment where setting DEBUG is false, Django sends log messages with ERROR or CRITICAL levels to AdminEmailHandler. This includes HTTP 5xx responses, which are handled by the django.request logger.

If you don’t have outbound email configured you lose these errors.

Python’s logging.StreamHandler defaults to sending output to stderr, and most of the time my Django applications are managed by systemd service units which default to passing stdout and stderr to systemd’s journal.

Put all of that knowledge together and here’s the delightfully simple LOGGING configuration I usually add to my production settings:

LOGGING = {
    "version": 1,
    "disable_existing_loggers": False,
    "handlers": {
        "stderr": {
            "class": "logging.StreamHandler"
        }
    },
    "loggers": {
        "django.request": {
            "level": "ERROR",
            "handlers": ["stderr"]
        }
    }
}

I can then fumble about with journald as required.

Apple continues their mission to drive me away

I used Pages to create a document a couple of weeks ago - something I very rarely do - and was presented with this advertisement for Apple Creator Studio when I selected a template:

Screenshot of advertisement for Apple Creator Studio

Then at the weekend I got this advertisement on my iPhone’s lock screen after paying for breakfast:

Screenshot of notification to join rewards program

No idea how I turn that kind of crap off, because “Offers & Promotions” is already disabled in my Apple Wallet notification settings:

Screenshot of Apple Wallet notification settings

Then a load of sloppiness this morning after updating my iPhone to iOS 26.4 when I was asked to double-click the side button to let stuff verify my age via Apple Wallet. That was the gist of it anyway. I don’t want that shit so I dismissed the prompt without thinking too much about it.

But then it threw up a dialogue with this content (I couldn’t take screenshots):

Parental Consent

To provide parental consent to create this child account, you will need to verify your identity by confirming the password for your account.

I’m not creating a child account! I’m not creating any account!

I played the game, then got this message. I haven’t replaced my actual email address - this is exactly what the message said, bold text and all:

Verification Code

To provide parental consent to create this child account, enter the verification code sent to this email address: email

Wealthiest company in the world. Thousands of employees. The premium Apple experience is a thing of the past.