• gunicorn的log如何传递给django,由django管理


    gunicorn配置文件为gunicorn_config.py里面有日志的配置

    # errorlog = '/home/admin/output/erebus/logs/gunicorn_error.log'
    # loglevel = 'info'
    # loglevel = 'debug'
    # accesslog = '/home/admin/output/erebus/logs/gunicorn_access.log'
    # access_log_format = '%(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"'
    

    django如何捕获gunicorn的日志

    注释掉上面的配置,则相关日志不输出,然后在django日志配置里添加

    logconfig_dict = {
    'version':1,
    'disable_existing_loggers': False,
    'loggers':{
        "gunicorn.error": {
            "level": "DEBUG",# 打日志的等级可以换的,下面的同理
            "handlers": ["error_file"], # 对应下面的键
            "propagate": 1,
            "qualname": "gunicorn.error"
        },
    
        "gunicorn.access": {
            "level": "DEBUG",
            "handlers": ["access_file"],
            "propagate": 0,
            "qualname": "gunicorn.access"
        }
    },
    'handlers':{
        "error_file": {
            "class": "logging.handlers.RotatingFileHandler",
            "maxBytes": 1024*1024*1024,# 打日志的大小,我这种写法是1个G
            "backupCount": 1,# 备份多少份,经过测试,最少也要写1,不然控制不住大小
            "formatter": "generic",# 对应下面的键
            # 'mode': 'w+',
            "filename": "/你要放日志的路径/gunicorn.error.log"# 打日志的路径
        },
        "access_file": {
            "class": "logging.handlers.RotatingFileHandler",
            "maxBytes": 1024*1024*1024,
            "backupCount": 1,
            "formatter": "generic",
            "filename": "/你要放日志的路径/gunicorn.access.log",
        }
    },
    'formatters':{
        "generic": {
            "format": "'[%(process)d] [%(asctime)s] %(levelname)s [%(filename)s:%(lineno)s] %(message)s'", # 打日志的格式
            "datefmt": "[%Y-%m-%d %H:%M:%S %z]",# 时间显示方法
            "class": "logging.Formatter"
        },
        "access": {
            "format": "'[%(process)d] [%(asctime)s] %(levelname)s [%(filename)s:%(lineno)s] %(message)s'",
            "class": "logging.Formatter"
        }
    }
    }
  • 相关阅读:
    理解cookie和session机制
    http协议中connection头的作用
    [转]使用Wireshark来检测一次HTTP连接过程
    http协议学习系列
    xcode清空project list
    How To Use Git Source Control with Xcode in iOS 6
    iOS开发XCODE5 SVN配置 使用办法
    iOS申请证书,Certificates, Identifiers &Profiles 简介
    C#学习单向链表和接口 IList<T>
    halcon学习笔记——(7)HALCON标定后的二维测量
  • 原文地址:https://www.cnblogs.com/shengulong/p/11167451.html
Copyright © 2020-2023  润新知