#Django not request logging

53 messages · Page 1 of 1 (latest)

upbeat geyser
#

This screams to me a code issue, yet after an hour of research I am still unsure as to why I can't see anything lower than a warning in the railway logs. The exact same branch, codebase, and env variables work fine, as I am able to see logs locally, but not on Railway. It was working a few months ago, but when I updated from django 3.2 to 4.0 and from heroku to nixpacks, the logging stopped showing up

stiff boughBOT
#

Project ID: 9b0e625c-b8d1-4c35-8629-60c32ab222ed

upbeat geyser
#

9b0e625c-b8d1-4c35-8629-60c32ab222ed

#

nixpacks.toml

#

[start]
cmd = 'python manage.py migrate && gunicorn --max-requests 1000 --workers 5 --threads 2 timeweb.wsgi'```
#

Django Logging config

    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'verbose': {
            'format': '{levelname} {asctime} {module} {process:d} {thread:d}>> {message}',
            'style': '{',
        },
        'simple': {
            'format': '{asctime} <<{levelname}>> {message}',
            'style': '{',
        },
    },
    'handlers': {
        'console': {
            'level': 'INFO',
            'class': 'logging.StreamHandler',
            'formatter': 'simple'
        },
        'mail_admins': {
            'level': 'ERROR',
            'class': 'django.utils.log.AdminEmailHandler',
        }
    },
    'loggers': {
        'django': {
            'handlers': ['console'],
            'propagate': True,
        },
        'django.request': {
            'handlers': ['mail_admins'],
            'level': 'ERROR',
            'propagate': False,
        },
    }
}```
lavish sinew
#

make sure your environment variable is set properly in the project, you could also just hard code them to test it

upbeat geyser
#

interesting

#

not the environment variables

#

but python 3.8 logs it

#

while python 3.10 doesn't

#

i guess that fixed my error but that is a bit odd

lavish sinew
#

interesting

#

3.10 is a bit new iirc

#

3.9 is the recommended for prod last i checked

upbeat geyser
#

i can try redeploying with 3.9 just to single out which version is causing the issue

#

3.9 works

#

it does indeed seem to be 3.10

lavish sinew
#

figures

upbeat geyser
#

hello,

I'm running into a similar problem from my original question for this thread. Info logging works but request logging on the other hand does not.

#

locally this works perfectly

#

but on railway it doesn't log requests

#

django's logger api works from views.py which means i can get my own log messages to work if I call it on a view function

#

which is pretty strange since my env variables are the same

#

as i mentioned in the original thread this worked on heroku way back ago but it just stopped working out of no where

#

Django not request logging

#

logging config (copied from django docs)

    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'verbose': {
            'format': '{levelname} {asctime} {module} {process:d} {thread:d}>> {message}',
            'style': '{',
        },
        'simple': {
            'format': '{asctime} <<{levelname}>> {message}',
            'style': '{',
        },
    },
    'handlers': {
        'console': {
            'level': 'INFO',
            'class': 'logging.StreamHandler',
            'formatter': 'simple'
        },
        'mail_admins': {
            'level': 'ERROR',
            'class': 'django.utils.log.AdminEmailHandler',
        }
    },
    'loggers': {
        'django': {
            'handlers': ['console'],
            'propagate': True,
        },
        'django.request': {
            'handlers': ['mail_admins'],
            'level': 'ERROR',
            'propagate': False,
        },
    }
}```
sinful night
#

this may be a shot in the dark but try setting PYTHONUNBUFFERED = 1 in the service variables

upbeat geyser
#

i already have that

#

i tried that from searcing through other threads

sinful night
#

well I did say shot in the dark

upbeat geyser
#

true lol

sinful night
#

are the info logs somehow going to a file and not stdout?

upbeat geyser
#

nope they've only been configured for stdout

#

hm

#

to try to pinpoint which end of the issue it is at

sinful night
#

maybe Django's logger doesn't respect the python unbuffered variable

upbeat geyser
#

i doubt it's a buffer issue

#

there are logs still showing up

#

manual calls to logger still show up in the logs

#

and tail appropriately

sinful night
#

so info logs trigger by routes just aren't getting logged

upbeat geyser
#

yes

#

everything else is logging

sinful night
upbeat geyser
#

yes

upbeat geyser
sinful night
#

fishy

upbeat geyser
#

hello, any update on this?

upbeat geyser
#

interestingly enough, it works a few days later