0

I've been breaking my head over creating a simple logfile within my django application. I've tried applying this question, as well as the examples on the docs, but it simply doesn't seem to work and I don't know what is going wrong.

My current logfile, second example straight from the doc:

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

The docs states the following:

"this config only sends messages of level INFO or higher to the console"

In my understanding, if I were to place this into my home.view.py file...

import logging
log = logging.getLogger(__name__)
log.debug("Hey there it works!!")
log.info("Hey there it works!!")
log.warn("Hey there it works!!")
log.error("Hey there it works!!")

...i should get the info, the warn and the error message printed to my console, whenever a call is made to home.views.py, which I thought happens when I visit the correct url.

This appears to be false. It seems however that only warn and error is printed, and only when I run manage.py collectstatic.

WARNING:home.views:Hey there it works!!
ERROR:home.views:Hey there it works!!

I want to receive the log messages in console, whenever I visit a webpage that's rendered from home.views.py. How do I do this?

Mitchell van Zuylen
  • 3,905
  • 4
  • 27
  • 64

1 Answers1

0

This method:

os.getenv('DJANGO_LOG_LEVEL', 'INFO')

First tries to get the environment variable if set. If not set then it defaults to the second argument. Its possible DJANGO_LOG_LEVEL is set to something higher than INFO.

To test this hypothesis run the following in your environment.

echo $DJANGO_LOG_LEVEL

Make sure its either 1. not set, or 2. set to INFO

export DJANGO_LOG_LEVEL=INFO
miketery
  • 111
  • 1
  • 7