Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Location of Django logs and errors

Tags:

django

I've set up django server with nginx, and it gets 403 error in some of the pages.

Where can I find the django logs? where can I see the errors in detail?

like image 701
Yoni Doe Avatar asked Oct 08 '13 19:10

Yoni Doe


People also ask

Where does Django log by default?

By default, it points at Python's logging. config. dictConfig() function. However, if you want to use a different configuration process, you can use any other callable that takes a single argument.

What is Django logging?

Python's logging library provides several techniques to configure logging, ranging from a programmatic interface to configuration files. By default, Django uses the dictConfig format. In order to configure logging, you use LOGGING to define a dictionary of logging settings.

Does Django have log requests?

django. request will log only 4xx and 5xx requests.


2 Answers

Logs are set in your settings.py file. A new, default project, looks like this:

# A sample logging configuration. The only tangible logging # performed by this configuration is to send an email to # the site admins on every HTTP 500 error when DEBUG=False. # See http://docs.djangoproject.com/en/dev/topics/logging for # more details on how to customize your logging configuration. LOGGING = {     'version': 1,     'disable_existing_loggers': False,     'filters': {         'require_debug_false': {             '()': 'django.utils.log.RequireDebugFalse'         }     },     'handlers': {         'mail_admins': {             'level': 'ERROR',             'filters': ['require_debug_false'],             'class': 'django.utils.log.AdminEmailHandler'         }     },     'loggers': {         'django.request': {             'handlers': ['mail_admins'],             'level': 'ERROR',             'propagate': True,         },     } } 

By default, these don't create log files. If you want those, you need to add a filename parameter to your handlers

    'applogfile': {         'level':'DEBUG',         'class':'logging.handlers.RotatingFileHandler',         'filename': os.path.join(DJANGO_ROOT, 'APPNAME.log'),         'maxBytes': 1024*1024*15, # 15MB         'backupCount': 10,     }, 

This will set up a rotating log that can get 15 MB in size and keep 10 historical versions.

In the loggers section from above, you need to add applogfile to the handlers for your application

'loggers': {         'django.request': {             'handlers': ['mail_admins'],             'level': 'ERROR',             'propagate': True,         },         'APPNAME': {             'handlers': ['applogfile',],             'level': 'DEBUG',         },     } 

This example will put your logs in your Django root in a file named APPNAME.log

like image 93
Andy Avatar answered Oct 06 '22 11:10

Andy


Add to your settings.py:

LOGGING = {     'version': 1,     'disable_existing_loggers': False,     'handlers': {         'file': {             'level': 'DEBUG',             'class': 'logging.FileHandler',             'filename': 'debug.log',         },     },     'loggers': {         'django': {             'handlers': ['file'],             'level': 'DEBUG',             'propagate': True,         },     }, } 

And it will create a file called debug.log in the root of your. https://docs.djangoproject.com/en/1.10/topics/logging/

like image 34
chezwhite Avatar answered Oct 06 '22 12:10

chezwhite