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

    在setting里加入如下配置,然后在代码中用就好了,至于为什么,看官网文档,这里的代码只是一个典型的配置

    # 自定义日志输出信息
    LOGGING = {
        'version': 1,
        'disable_existing_loggers': True,
        'formatters': {
            'standard': {
                'format': '%(asctime)s [%(threadName)s:%(thread)d] [%(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': 'log/all.log',     #日志输出文件
                'maxBytes': 1024*1024*5,                  #文件大小
                'backupCount': 5,                         #备份份数
                'formatter':'standard',                   #使用哪种formatters日志格式
            },
            'error': {
                'level':'ERROR',
                'class':'logging.handlers.RotatingFileHandler',
                'filename': 'log/error.log',
                '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': 'log/script.log',
                'maxBytes': 1024*1024*5,
                'backupCount': 5,
                'formatter':'standard',
                },
            'scprits_handler': {
                'level':'DEBUG',
                'class':'logging.handlers.RotatingFileHandler',
                'filename':'log/script.log',
                'maxBytes': 1024*1024*5,
                'backupCount': 5,
                'formatter':'standard',
                }
        },
        'loggers': {
            'django': {
                'handlers': ['default', 'console'],
                'level': 'DEBUG',
                'propagate': False
            },
            'django.request': {
                'handlers': ['request_handler'],
                'level': 'DEBUG',
                'propagate': False,
                },
            'scripts': {
                'handlers': ['scprits_handler'],
                'level': 'INFO',
                'propagate': False
            },
            'myapp.views': {
                'handlers': ['default', 'error'],
                'level': 'DEBUG',
                'propagate': True
            },
        }
    }
  • 相关阅读:
    使用UOS微信桌面版协议登录,wechaty免费版web协议又可以用了
    angular之$watch方法详解
    webpack配置这一篇就够
    select设置disable后ie修改默认字体颜色暂时解决
    201901251946
    new year
    test
    mysql密码忘记解决方法
    bianmayujianmatest
    jinzhizhuanhuan
  • 原文地址:https://www.cnblogs.com/413xiaol/p/6852192.html
Copyright © 2011-2022 走看看