zoukankan      html  css  js  c++  java
  • django logging

    LOG_LEVEL='DEBUG'
    LOGGING = {
        'version': 1,
        'disable_existing_loggers': False,
        'formatters': {
            'verbose': {
                'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s',
            },
            'normal': {
                'format': '%(asctime)s [%(levelname)s] %(module)s/%(filename)s[line:%(lineno)d] %(message)s',
                'datefmt':'%Y%m%d %H:%M:%S',
            },
            'test':{
                'format':'%(asctime)s %(module)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s'
            }
        },
    
        'handlers': {
            'null': {
                'level': 'DEBUG',
                'class': 'logging.NullHandler',
            },
            'console': {
                'level': 'DEBUG',
                'class': 'logging.StreamHandler',
                'formatter': 'normal'
            },
            'logfile': {
                'level': 'DEBUG',
                'class': 'logging.FileHandler',
                'filename': os.path.join(BASE_DIR, 'logs','server.log'),
                'formatter': 'normal'
            },
            'ansible_logfile': {
                'level': 'DEBUG',
                'class': 'logging.FileHandler',
                'formatter': 'normal',
                'filename': os.path.join(BASE_DIR, 'logs', 'ansible.log'),
            },
            'test_logfile': {
                'level': 'DEBUG',
                'class': 'logging.FileHandler',
                'filename': os.path.join(BASE_DIR, 'logs','test.log'),
                'formatter': 'test'
            }
    
        },
        'loggers': {
            'django': {
                'handlers': ['console', 'logfile'],
                'level': 'INFO',
                'propagate': False,
            },
            'appcommon': {
                'handlers': ['console', 'logfile'],
                'level': LOG_LEVEL,
                'propagate': False,
            },
    
            'app01.views': {
                'handlers': ['console', 'test_logfile'],
                'level': LOG_LEVEL,
                'propagate': False
            },
            'app01': {
                'handlers': ['console', 'logfile'],
                'level': LOG_LEVEL,
                'propagate': False
            },
            'ansible': {
                'handlers': ['console', 'ansible_logfile'],
                'level': LOG_LEVEL,
                'propagate': False
            },
    
    
        }
    }

    使用

    # Create your views here.
    import logging
    logger=logging.getLogger(__name__)   # 优先使用完全匹配,若找不到,app01也行
    
    def index(request):
        print(__name__)
        logger.error('eeee')
  • 相关阅读:
    图论算法(三) 最短路SPFA算法
    图论算法(二)最短路算法:Floyd算法!
    图论算法(一)存图与STL第六弹——vector容器
    C++指针变量的基本写法
    杂记——深度优先搜索(dfs)与出题感想
    分治算法(二分查找)、STL函数库的应用第五弹——二分函数
    网站开发小技巧总结
    网站开发动态效果插件
    jquery获得ul下li的个数
    jquery的循环函数和点击事件绑定
  • 原文地址:https://www.cnblogs.com/infaaf/p/9503070.html
Copyright © 2011-2022 走看看