Django Dumpdata file contains debug logs

851 Views Asked by At

I'm dumping some data from my django app with the command python manage.py dumpdata > db.json

Unfortunately the db.json contains some startup logs in the first lines of the files.

The file looks like:

DEBUG $HOME=/home/web
DEBUG matplotlib data path /usr/local/lib/python3.5/dist-packages/matplotlib/mpl-data
DEBUG loaded rc file /usr/local/lib/python3.5/dist-packages/matplotlib/mpl-data/matplotlibrc
DEBUG matplotlib version 2.2.2
DEBUG interactive is False
DEBUG platform is linux
[{ ... then the json file ... }]

I guess it's coming from my logs configuration, but I couldn't figured it out.

Here is my logs config in setting.py:

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'filters': {
        'require_debug_false': {
            '()': 'django.utils.log.RequireDebugFalse',
        },
        'require_debug_true': {
            '()': 'django.utils.log.RequireDebugTrue',
        },
    },
    'formatters': {
        'verbose': {
            'format': '%(asctime)s %(levelname)s [%(module)s:%(funcName)s:%(lineno)d] %(message)s',
        },
        'simple': {
            'format': '%(levelname)s %(message)s',
        },
    },
    'handlers': {
        'console_simple': {
            'class': 'logging.StreamHandler',
            'filters': ['require_debug_true'],
            'formatter': 'simple',
            'level': 'DEBUG',
        },
        'console_verbose': {
            'class': 'logging.StreamHandler',
            'filters': ['require_debug_false'],
            'formatter': 'verbose',
            'level': 'INFO',
        },
    },
    'loggers': {
        'django.request': {
            'handlers': ['console_simple', 'console_verbose'],
            'level': 'ERROR',
            'propagate': False,
        },
    },
    'root': {
        'handlers': ['console_simple', 'console_verbose'],
        'level': 'DEBUG',
    },
}

Any ideas?

1

There are 1 best solutions below

1
Bob On BEST ANSWER

It is because you are redirecting all output from the command to your file. Django's dumpdata command also takes an output parameter where to store the generated file: https://docs.djangoproject.com/en/2.1/ref/django-admin/#cmdoption-dumpdata-output

Basically instead of > file.json use --output file.json.