码迷,mamicode.com
首页 > 其他好文 > 详细

django logging

时间:2018-08-19 23:21:35      阅读:236      评论:0      收藏:0      [点我收藏+]

标签:erb   gate   format   djang   log   handlers   dex   ble   att   

 

 

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

标签:erb   gate   format   djang   log   handlers   dex   ble   att   

原文地址:https://www.cnblogs.com/infaaf/p/9503070.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!