logging example for Django >1.3 on a shared hosting webserver

    Published on August 18, 2014

    Every one who has already worked with Django, appreciate its useful logging information in the browser when the DEBUG modus is on while you are testing your project on a localhost developement server. But it is always helpful to have a log file stored instead of showing all of Djangos logging information in the browser, especially on a production server, where you should have usually set DEBUG = False, due to security reasons.

    By default Django version >1.3 is providing logging functionality in the file, when you start a new project with python startproject <project_name>. In this short blog I will show you how I configure Django to write a readable log file on my production server, that is a shared hosting webserver without any console access:

    import logging
    LOGGING = {
        'version': 1,
        'disable_existing_loggers': False,
        'formatters': {
            'verbose': {
                'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
        'handlers': {
            'file': {
                'level': 'DEBUG',
                'formatter': 'verbose',
                'class': 'logging.FileHandler',
                'filename': os.path.join(CURRENT_PATH, '../django.log'),
        'loggers': {
            'django.request': {
                'handlers': ['file'],
                'level': 'DEBUG',
                'propagate': True,
    # Get an instance of a logger
    logger = logging.getLogger('django.request')
    logger.debug("start logging")

    This simple logging configuration is going to log in a file called django.log which stores ERROR, WARNING and INFO messages, because the lowest log level DEBUG is set. The log messages will have the following format:

    ERROR 2014-08-18 14:48:29,302 base 6580 139672609781568 Internal Server Error: /de/contact/

    For more information see


    So far, this entry has 0 comments.

    Post a comment

Buchempfehlungen pix pix
May 2019
Über pix

Ich bin Diplom Informatiker und das ist meine persönliche Internet sowie weblog Seite.mehr Informationen...