skip to Main Content

I have some debugging statements that I need to print out from my Django out, but I cannot find which file to look for them. They do not appear in the access logs or the error logs. Where can I find the file which they appear?

2

Answers


  1. They appear in your console where you run : python manage.py runserver
    Of course you need to trigger the functions where there are prints so they execute it.

    Login or Signup to reply.
  2. For anyone else who comes here later: I had to, on my local laptop, add this to my settings.py to get print statements to appear on my console:

    https://docs.djangoproject.com/en/2.1/topics/logging/#examples

    The second example shows how to print to console:

    import os
    
    LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'console': {
            'class': 'logging.StreamHandler',
        },
    },
    'loggers': {
        'django': {
            'handlers': ['console'],
            'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'),
        },
    },
    }
    

    I don’t recall having to do this in years/django versions past, so either this used to be in the settings by default, or more likely it’s something that got changed so now you have to specify this in settings.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search