django logging

Posted infaaf

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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)

 

以上是关于django logging的主要内容,如果未能解决你的问题,请参考以下文章

django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE的解决办法(转)(代码片段

django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE的解决办法(转)(代码片段

我的Android进阶之旅NDK开发之在C++代码中使用Android Log打印日志,打印出C++的函数耗时以及代码片段耗时详情

python常用代码片段总结

前端开发常用js代码片段

vs code 自定义代码片段