zoukankan      html  css  js  c++  java
  • Title

    django的日志配置文件

    放入settings.py中

    # logger
    import datetime
    LOGGING = {
        'version': 1,
        'disable_existing_loggers': True,
        'formatters': {
            'standard': {
                'format': '%(asctime)s [%(name)s:%(lineno)d] [%(module)s:%(funcName)s] [%(levelname)s] %(message)s'}
        },
        'filters': {
        },
        'handlers': {
            'mail_admins': {
                'level': 'ERROR',
                'class': 'django.utils.log.AdminEmailHandler',
                'include_html': True,
            },
            'default': {
                'level': 'DEBUG',
                'class': 'logging.handlers.RotatingFileHandler',
                'filename': '{}/engine_{}.log'.format("/var/log/project", datetime.datetime.now().date()),  # 日志输出文件
                'maxBytes': 1024 * 1024 * 5,  # 文件大小
                'backupCount': 5,  # 备份份数
                'formatter': 'standard',  # 使用哪种formatters日志格式
            },
            'error': {
                'level': 'ERROR',
                'class': 'logging.handlers.RotatingFileHandler',
                'filename': '{}/engine_Error_{}.log'.format("/var/log/project", datetime.datetime.now().date()),
                'maxBytes': 1024 * 1024 * 5,
                'backupCount': 5,
                'formatter': 'standard',
            },
            'console': {
                'level': 'DEBUG',
                'class': 'logging.StreamHandler',
                'formatter': 'standard'
            },
            'request_handler': {
                'level': 'DEBUG',
                'class': 'logging.handlers.RotatingFileHandler',
                'filename': '{}/engine_Request_{}.log'.format("/var/log/project", datetime.datetime.now().date()),
                'maxBytes': 1024 * 1024 * 5,
                'backupCount': 5,
                'formatter': 'standard',
            },
            'scripts_handler': {
                'level': 'DEBUG',
                'class': 'logging.handlers.RotatingFileHandler',
                'filename': '{}/engine_Script_{}.log'.format("/var/log/project", datetime.datetime.now().date()),
                'maxBytes': 1024 * 1024 * 5,
                'backupCount': 5,
                'formatter': 'standard',
            }
        },
        'loggers': {
            # 框架本身运行相关日志
            # 'django': {
            #     'handlers': ['default'],
            #     'level': 'DEBUG',
            #     'propagate': False
            # },
            'django.request': {
                'handlers': ['request_handler'],
                'level': 'DEBUG',
                'propagate': False,
            },
            'scripts': {
                'handlers': ['scripts_handler'],
                'level': 'INFO',
                'propagate': False
            },
            # 只输出到控制台,不写入日志文件
            'console': {
                'handlers': ['console'],
                'level': 'DEBUG',
                'propagate': True
            },
            # app engine 模块的日志处理 并输出到控制台
            'engine': {
                'handlers': ['default', 'error', 'console'],
                'level': 'DEBUG',
                'propagate': True
            },
            # 日志写入上面handlers定义的error所指向的log日志文件 并输出到控制台
            'app01': {
                'handlers': ['error', 'console'],
                'level': 'ERROR',
                'propagate': True
            },
            # 日志同时写入上面handlers定义的default和error所指向的log日志文件
            'app02': {
                'handlers': ['default', 'error'],
                'level': 'ERROR',
                'propagate': True
            },
        }
    }
    

    在调用的地方

    import logging
    logger = logging.getLogger("app01")
    
  • 相关阅读:
    【转】数据库中查询记录时是否每次只能使用一个索引?
    【转】MySQL理解索引、添加索引的原则
    【转】.htaccess详解及.htaccess参数说明
    【转】BASE64编码简介
    【转】联想笔记本进入u盘启动项操作方法详解
    【转】UEFI是什么?与BIOS的区别在哪里?UEFI详解!
    55. Jump Game
    54. Spiral Matrix
    53. Maximum Subarray
    52. N-Queens II
  • 原文地址:https://www.cnblogs.com/guotianbao/p/13695173.html
Copyright © 2011-2022 走看看