zoukankan      html  css  js  c++  java
  • Django 配置使用日志

    一. Django中使用日志

      Django中使用日志其实非常简单,只需要在项目使用的配置文件中(如果没有自定义,那么就是settings.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
                'level': 'INFO',
                'class': 'logging.handlers.RotatingFileHandler',
                # 日志位置,日志文件名,日志保存目录必须手动创建,然后给对应的路径即可 注:这里的文件路径要注意BASE_DIR
                'filename': os.path.join(os.path.dirname(BASE_DIR), "logs/manage.log"),
                # 日志文件的最大值,这里我们设置300M
                'maxBytes': 300 * 1024 * 1024,
                # 日志文件的数量,设置最大日志数量为10
                'backupCount': 10,
                # 日志格式:详细格式
                'formatter': 'verbose',
                # 设置日志中的编码
                'encoding': 'utf-8'
            },
        },
        # 日志对象
        'loggers': {
            'django': {
                'handlers': ['console', 'file'],
                'propagate': True,  # 是否让日志信息继续冒泡给其他的日志处理系统
            },
        }
    }
  • 相关阅读:
    最新Linux系统Ubuntu16.04搭建HUSTOJ(LAMP环境)
    deepin下codeblocks更改调试终端
    UVA
    POJ3436 ACM Computer Factory【EK算法】
    HDU4738 Caocao's Bridges【强连通】
    HDU4685 Prince and Princess【强连通】
    HDU4635 Strongly connected【强连通】
    POJ3177 Redundant Paths【双连通分量】
    HDU1233 还是畅通工程【最小生成树】
    3D正方体
  • 原文地址:https://www.cnblogs.com/maoruqiang/p/11246906.html
Copyright © 2011-2022 走看看