Search code examples
javascriptdjangoconsolestderrdaphne

JavaScript console.error redirect to file in Daphne Django application


I am using systemd (on Debian) to launch a shell script (as me as a user):

startup.sh:

#/bin/bash
daphne -b '0.0.0.0' -p 8000 myProject.asgi:application 2> /tmp/log.out

In my Python (Django) application I need to output to stdout and have it show up on the screen (tty1), which is working fine. The problem is that the JavaScript console.error() messages are also showing up on the screen even though I am redirecting stderr when launching Daphne. Is there an easy way to have the JavaScript stderr also redirect to a file? (could be the same or a different file than /tmp/log.out)

My systemd service config is:

[Unit]
Description=Run my Django test server
DefaultDependencies=no
[email protected]

[Service]
User=pi
Type=simple
WorkingDirectory=/opt/myModule
ExecStart=bash /opt/myModule/startup.sh
Restart=always
RestartSec=5
StandardOutput=tty
StandardError=journal
TTYPath=/dev/tty1
TTYVHangup=yes
TTYReset=yes

[Install]
WantedBy=basic.target

Solution

  • The extra logging was coming from Daphne. I was able to redirect it to a log file by adding the --access-log flag:

    daphne --access-log /tmp/daphne.log -b '0.0.0.0' -p 8000 myProject.asgi:application 2> /tmp/log.out