3

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

python manage.py runserver>>Log.txt?

Brian Webster
  • 30,033
  • 48
  • 152
  • 225
IT Ninja
  • 6,174
  • 10
  • 42
  • 65

2 Answers2

4

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

Example for you

Community
  • 1
  • 1
San4ez
  • 8,091
  • 4
  • 41
  • 62
  • 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 ^.^. – IT Ninja Apr 14 '12 at 14:53
  • @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](http://stackoverflow.com/questions/27563706/logging-django-request-to-file-instead-of-console) – stratis Dec 19 '14 at 11:14
  • For future visitors: Django `runserver` has used the `logging` module since version 1.10. Previously, logging from `runserver` was written to `sys.stderr`. – bitoffdev Jun 05 '19 at 20:55
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.

Akif
  • 6,018
  • 3
  • 41
  • 44