zoukankan      html  css  js  c++  java
  • Django 日志

    例:setting配置

    import logging
    import os
    
    # LOG_DIR = "/var/log/dt_logs"
    LOG_DIR = "./"
    # if not os.path.exists(LOG_DIR):
    #     os.mkdir(LOG_DIR)
    
    LOGGING = {
        "version": 1,
        "disable_existing_loggers": False,
        "filters": {"require_debug_false": {"()": "django.utils.log.RequireDebugFalse"}},
        "formatters": {
            "standard": {
                "format": "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s",
                "datefmt": "%Y-%m-%d %H:%M:%S",
            }
        },
        # 指定输出到控制台还是文件中,以及输出的方式。被logger引用。
        "handlers": {
            # 输出到控制台
            "console": {
                "level": "DEBUG",
                "class": "logging.StreamHandler",
                "formatter": "standard",
            },
            "test_log": {
                "level": "ERROR",
                "class": "logging.handlers.RotatingFileHandler",
                "formatter": "standard",
                # 存放的日志的位置
                "filename": os.path.join(LOG_DIR, "test.log"),
                "maxBytes": 1024 * 1024 * 100,
                "backupCount": 5,
            },
            "mail_admins": {
                "level": "ERROR",
                "filters": ["require_debug_false"],
                "class": "django.utils.log.AdminEmailHandler",
            },
    
        },
        # 指定django中的每个模块使用哪个handlers。以及日志输出的级别。
        "loggers": {
            "django": {"handlers": ["test_log"], "propagate": True, "level": "INFO"},
    
            "test_log": {
                # 使用哪一个 handlers
                "handlers": ["test_log"],
                "propagate": True,
                "level": "ERROR",
            },
    
        },
    }

    views

    import logging
    logger = logging.getLogger("test_log")
    def test_log(request):
        print(logger.error("error"))
        return "hello......"
  • 相关阅读:
    RAM disk
    将2个物理磁盘做成4个逻辑卷
    LVM——基本概念
    服务器CPU架构演变过程
    IBM XIV
    011——一些貌似高逼格的词汇
    010——存储系统架构演变
    010——集群化
    009——虚拟化
    008——协议融合
  • 原文地址:https://www.cnblogs.com/yu121/p/14470979.html
Copyright © 2011-2022 走看看