Dmitry Yudin
Dmitry Yudin

Reputation: 978

How to get all prints on django production server with apache

Please tell me how can I get all prints that I see when I run ./manage.py runserver locally. I dont want to use logger. Ideally I would like to connect to my manage.py and see what is server is printing for me now. I tried django print information on production server with no success. I know that i cat just tail -f logfile and i will see last lines, but i could not find where is my prints located. Please help. Here is my logging config:

LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
    'require_debug_false': {
        '()': 'django.utils.log.RequireDebugFalse'
    },
    'require_debug_true': {
        '()': 'django.utils.log.RequireDebugTrue'
    }
},
'formatters': {
    'main_formatter': {
        'format': '%(levelname)s:%(name)s: %(message)s '
                 '(%(asctime)s; %(filename)s:%(lineno)d)',
        'datefmt': "%Y-%m-%d %H:%M:%S",
    },
},
'handlers': {
    'mail_admins': {
        'level': 'ERROR',
        'filters': ['require_debug_false'],
        'class': 'django.utils.log.AdminEmailHandler'
    },
    'console':{
        #'level': 'DEBUG',
        'level': 'ERROR',
        'filters': ['require_debug_true'],
        'class': 'logging.StreamHandler',
        'formatter': 'main_formatter',
    },
    'production_file':{
        'level' : 'INFO',
        'class' : 'logging.handlers.RotatingFileHandler',
        'filename' : 'logs/main.log',
        'maxBytes': 1024*1024*5, # 5 MB
        'backupCount' : 7,
        'formatter': 'main_formatter',
        'filters': ['require_debug_false'],
    },
    'debug_file':{
        'level' : 'DEBUG',
        'class' : 'logging.handlers.RotatingFileHandler',
        'filename' : 'logs/main_debug.log',
        'maxBytes': 1024*1024*5, # 5 MB
        'backupCount' : 7,
        'formatter': 'main_formatter',
        'filters': ['require_debug_true'],
    },
    'null': {
        "class": 'django.utils.log.NullHandler',
    }
},
'loggers': {
    'django.request': {
        'handlers': ['mail_admins', 'console'],
        'level': 'ERROR',
        'propagate': True,
    },
    'django': {
        'handlers': ['null', ],
    },
    'py.warnings': {
        'handlers': ['null', ],
    },
    '': {
        'handlers': ['console', 'production_file', 'debug_file'],
        'level': "DEBUG",
    },
}

}

Upvotes: 1

Views: 1754

Answers (2)

Alexandr Faizullin
Alexandr Faizullin

Reputation: 66

If you run your application in production setup, i.e. APACHE server your can find prints in file located in destination, which you configured in your apache config. For example: 'ErrorLog /var/log/httpd-error.log'

Upvotes: 3

GwynBleidD
GwynBleidD

Reputation: 20569

Django can be run as multi-threaded server without master, so there is no simple way to join all std output together. Logging is simplest and best solution here, you can define many log handlers, even send all logs into some socket, where some simple logging server will reside that will catch all logs and print them into console. Running that server on screen will allow you to connect to it and see some last messages from it.

Upvotes: 1

Related Questions