Louis Kwon
Louis Kwon

Reputation: 31

Django Logging not outputting to log file on nginx server

My Django Logger works fine on my local machine but does not work when I deploy it to the server.

Local: OS X 10.9.5, Python 2.7, Django 1.10.5

AWS Server: Ubuntu, Nginx, Gunicorn, Django

On my local setup I run python manage.py runserver, this creates the debug.log file in my root directory. I access the site through localhost:8000 when I boot up the local server via virtual environment and I get these logs on my debug.log.

"GET / HTTP/1.1" 200 2908
"GET /projects HTTP/1.1" 200 3461
Inside app views index

On my production server I run python manage.py runserver, this creates the debug.log file. I restart Nginx server by sudo service nginx restart, and I access my webpage and click on the same links as when I was running the local server.

When I vim debug.log into the debug.log file, I can not see any of my debug messages after I visit the website and click on the same links in the webpage.

Why is there no logging data being recorded into debug.log on my production environment? What am I missing?

views.py

import logging
logger = logging.getLogger(__name__)

def index(request):
    logger.debug('Inside app views index')
    return render(request, "first_app/index.html")

local_settings.py (It shouldn't matter, but I am using local_settings.py in my local machine and production server)

#BASE_DIR was already part of django settings.py file when created.
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'file': {
            'level': 'DEBUG',
            'class': 'logging.FileHandler',
            'filename': os.path.join(BASE_DIR, 'debug.log'),
        },
        'null': {
            'class': 'logging.NullHandler',
        },
    },
    'loggers': {
        'django': {
            'handlers': ['file'],
            'level': 'DEBUG',
            'propagate': True,
        },
        'apps': {
            'handlers': ['file'],
            'level': 'DEBUG',
            'propagate': True,
        },
        'django.db.backends': {
            'handlers': ['null'],
            'propagate': False,
        },
    },
}

My file routes are

-homepage
  -apps
  -homepage
  -static
  -venv
  manage.py
  homepage.sock
  db.sqlite3
  debug.log
  requirement.txt

Upvotes: 3

Views: 3137

Answers (1)

user798719
user798719

Reputation: 9869

I believe that the requests (GET, POST, etc) logs are intercepted by Nginx and logged to its nginx-access.log, while your INFO, ERROR logs should be in debug.log

Upvotes: 1

Related Questions