Py学习  »  Django

django logging 日志处理方法

爱情的枪 • 9 年前 • 4155 次点击  

如果在执行django时,想要打印出DB的query执行情况,可以使用以下配置

LOGGING = {
    'disable_existing_loggers': False,
    'version': 1,
    'handlers': {
        'console': {
            # logging handler that outputs log messages to terminal
            'class': 'logging.StreamHandler',
            'level': 'DEBUG', # message level to be written to console
        },
    },
    'loggers': {
        '': {
            # this sets root level logger to log debug and higher level
            # logs to console. All other loggers inherit settings from
            # root level logger.
            'handlers': ['console'],
            'level': 'DEBUG',
            'propagate': False, # this tells logger to send logging message
                                # to its parent (will send if set to True)
        },
        'django.db': {
            # django also has database level logging
        },
    },
}

想要完整的可以看这里啦:https://docs.djangoproject.com/en/1.7/topics/logging/

欢迎大家讨论哦,日志也是很重要的一块

http://stackoverflow.com/questions/971667/django-orm-how-to-view-or-log-the-executed-query

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/691
 
4155 次点击  
文章 [ 1 ]  |  最新文章 9 年前
Py站长
Reply   •   1 楼
Py站长    9 年前

赞~!