D
D
Dauren S2016-10-27 13:29:56
Django
Dauren S, 2016-10-27 13:29:56

Django logging?

settings.py

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'file': {
            'level': 'DEBUG',
            'class': 'logging.FileHandler',
            'filename': '/path/to/django/debug.log',
        },
    },
    'loggers': {
        'django': {
            'handlers': ['file'],
            'level': 'DEBUG',
            'propagate': True,
        },
    },
}

in appviews.py
import logging
logger = logging.getLogger(__name__)
def show_article(request,url):
    article=Articles.objects.all()
    logger.debug(article)

in the application I need to write logs, the data that I received from the database or on which I did some operations,
i.e. print (list) type,
how can I write them to the logs?
By this code above is not recorded

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dauren S, 2016-10-27
@dauren101

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'file': {
            'level': 'DEBUG',
            'class': 'logging.FileHandler',
            'filename': '/path/to/django/debug.log',
        },
    },
    'loggers': {
        'news': {
            'handlers': ['file'],
            'level': 'DEBUG',
            'propagate': True,
        },
    },
}

M
Maxim Vasiliev, 2016-10-27
@qmax

The `__name__` variable denotes the name of the current module in the project context, i.e. = "yourapp.views"
And you only have logging enabled for `django.*`.
To enable for your module add loggers[yourapp]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question