3

Is it possible to output Django's runserver output into a text file? such as:

python manage.py runserver>>Log.txt?

2
  • Do you mean >> instead of <<? Commented Apr 14, 2012 at 14:42
  • You can also use getsentry.com which will capture all logging and provide a nice interface for you to search/filter. Commented Feb 17, 2013 at 8:11

2 Answers 2

4

Django uses python logging module and you can configure it in your settings.py to output into file.

Example for you

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you very much :) Im still newbie when it comes to Django. The help is very much appreciated and your check-mark is on the way ^.^.
@San4ez. No. Django uses the logging module. Not the Django development server. See here http://stackoverflow.com/questions/27563706/logging-django-request-to-file-instead-of-console
For future visitors: Django runserver has used the logging module since version 1.10. Previously, logging from runserver was written to sys.stderr.
0

You can achieve it by adding following lines into settings.py. This will both write a log file in DEBUG level and also display on console in INFO level.

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'file': {
            'level': 'DEBUG',
            'class': 'logging.handlers.RotatingFileHandler',
            'filename': /path/to/django/debug.log,
            'maxBytes': 50000,
            'backupCount': 2,
        },
        'console': {
            'level': 'INFO',
            'class': 'logging.StreamHandler',
        },
    },
    'root': {
        'handlers': ['file', 'console'],
        'level': 'DEBUG'
    },
    'loggers': {
        'django': {
            'handlers': ['file', 'console'],
            'level': 'DEBUG',
            'propagate': True,
        },
    },
}

Please also have a look Django documentaton for additional information.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.