zoukankan      html  css  js  c++  java
  • django配置日志

    配置日志:settings/dev.py

    # 官网:https://docs.djangoproject.com
    # 中文loggin配置:https://docs.djangoproject.com/zh-hans/2.2/topics/logging/
    
    LOGGING = {
        'version': 1,
        'disable_existing_loggers': False,
        'formatters': {
            'verbose': {
                'format': '%(levelname)s %(asctime)s %(module)s %(lineno)d %(message)s'
            },
            'simple': {
                'format': '%(levelname)s %(module)s %(lineno)d %(message)s'
            },
        },
        'filters': {
            'require_debug_true': {
                '()': 'django.utils.log.RequireDebugTrue',
            },
        },
        'handlers': {
            'console': {
                'level': 'DEBUG',
                'filters': ['require_debug_true'],
                'class': 'logging.StreamHandler',
                'formatter': 'simple'
            },
            'file': {
                # 实际开发建议使用WARNING或ERROR
                'level': 'INFO',
                'class': 'logging.handlers.RotatingFileHandler',
                # 日志位置,日志文件名,日志保存目录必须手动创建,注:这里的文件路径要注意BASE_DIR
                'filename': os.path.join(os.path.dirname(BASE_DIR), "logs/luffy.log"),
                # 日志文件的最大值,这里我们设置300M
                'maxBytes': 300 * 1024 * 1024,
                # 日志文件的数量,设置最大日志数量为10
                'backupCount': 10,
                # 日志格式:详细格式
                'formatter': 'verbose'
            },
        },
        # 日志对象
        'loggers': {
            'django': {
                'handlers': ['console', 'file'],
                'propagate': True,  # 是否让日志信息继续冒泡给其他的日志处理系统
            },
        }
    }

    配置logger:utils/logging.py

    import logging
    logger = logging.getLogger('django')

  • 相关阅读:
    01.html5+phonegap跨平台移动应用开发
    10个CSS简写/优化技巧
    JS高级学习历程-17
    JS高级学习历程-16
    算法详解之Tarjan
    分层图详解
    洛谷 题解 P1196 【[NOI2002]银河英雄传说】
    洛谷 题解 P1220 【关路灯 】
    洛谷 题解 P1352 【没有上司的舞会】
    二维前缀和详解
  • 原文地址:https://www.cnblogs.com/zhouze/p/11431696.html
Copyright © 2011-2022 走看看