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')

  • 相关阅读:
    linux系统如何发送邮件
    zabbix监测图形界面显示方框乱码解决方法
    Eclipse C++的配置问题launch failed binary not found
    Cpu表现出正弦曲线
    让cpu跑到100%的bat文件
    进程僵死
    华为一些笔试题~~~~零散总结
    数据库~~~投影与除操作
    C++连接Mysql数据库操作
    微软面试题目及答案
  • 原文地址:https://www.cnblogs.com/zhouze/p/11431696.html
Copyright © 2011-2022 走看看