1

I just set up new server and while I'm checking it, I got 500 error. I expect that debug.log file has error message, However, when I check the file the file was empty. Nothing was written. So I changed the loggers settings may times, but still the file is empty and I can't fix the error because what is wrong with it...

This is my views.py

logger = logging.getLogger(__name__)

put this line to do logging.

settings.py

LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
    'require_debug_false': {
        '()': 'django.utils.log.RequireDebugFalse'
    }
},
'formatters': {
    'simple': {
        'format': '%(asctime)s %(filename)s:%(lineno)d %(message)s',
    }
},
'handlers': {
    'file': {
        'level': 'DEBUG',
        'filters': ['require_debug_false'],
        'class': 'logging.handlers.RotatingFileHandler',
        'filename': '/var/log/service/debug.log',
        'formatter': 'simple',
    },
},
'loggers': {
    'django': {
        'handlers': ['file'],
        'level': 'ERROR',
        'propagate': True,
    },
}
}

if DEBUG:
    del LOGGING['loggers']['django']
    del LOGGING['handlers']['file']

if not os.path.exists('log'):
    os.makedirs('log')

I attached my wsgi.py

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")

application = get_wsgi_application()

This is settings.py where import local settings.

try:
    from local_settings import *
except ImportError:
    raise ImportError('You must create local_settings.py on project root')

This is local_settings.py

DEBUG=False
3
  • How are you using the logger object you created? Commented Jul 17, 2018 at 8:19
  • @ShahrukhMohammad logger object? Commented Jul 17, 2018 at 8:20
  • The one you created in your views.py file Commented Jul 17, 2018 at 8:22

2 Answers 2

4

You don't have logger named views in your settings. It's only logger named django there. So try to use it in views.py:

logger = logging.getLogger('django')
Sign up to request clarification or add additional context in comments.

3 Comments

@camila did you restart Django after changes?
I restarted uwsgi so yeah, I restarted Django after changes.
Thank you very much I was not passing logger name & it took 2-3 hours to find me this answer. It works!
0

what is the setting of DEBUG on your server?

because:

if DEBUG: del LOGGING['loggers']['django'] del LOGGING['handlers']['file']

if DEBUG is True you are deleting the logger and handler...

4 Comments

just checked, settings.py debug is True but I made local_settings.py, in here DEBUG=False.
are you sure you are loading local_settings.py? are you setting the environment variable or did you modify the wsgi.py? details...
I attached wsgi.py.
I still do not see where you are loading local_settings like you mentioned. Are you setting the environment variable?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.