kathir raja
kathir raja

Reputation: 1016

Where do print statements from Django app go?

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?

Upvotes: 1

Views: 1509

Answers (2)

rossdavidh
rossdavidh

Reputation: 1996

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.

Upvotes: 1

Ines Tlili
Ines Tlili

Reputation: 810

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.

Upvotes: 1

Related Questions