django configuration log

Configuration log: settings / dev.py

# 官网:https://docs.djangoproject.com
# 中文loggin配置:https://docs.djangoproject.com/zh-hans/2.2/topics/logging/

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'verbose': {
            'format': '%(levelname)s %(asctime)s %(module)s %(lineno)d %(message)s'
        },
        'simple': {
            'format': '%(levelname)s %(module)s %(lineno)d %(message)s'
        },
    },
    'filters': {
        'require_debug_true': {
            '()': 'django.utils.log.RequireDebugTrue',
        },
    },
    'handlers': {
        'console': {
            'level': 'DEBUG',
            'filters': [' Require_debug_true ' ],
             ' class ' : ' logging.StreamHandler ' ,
             ' Formatter ' : ' Simple ' 
        }, 
        ' File ' : {
             # actual development recommended WARNING, or ERROR 
            ' Level ' : ' the INFO ' ,
             ' class ' : ' logging.handlers.RotatingFileHandler ' ,
             #Log location, log file name, save the log directory must be created manually, Note: This file path should pay attention to base_dir 
            ' filename ' : os.path.join (os.path.dirname (base_dir), " logs / luffy.log " ) ,
             # log file maximum, where we set 300M 
            ' MaxBytes ' : 300 * 1024 * 1024 ,
             # number of log files, set the maximum number of logs for 10 
            ' BACKUPCOUNT ' : 10 ,
             # log format: verbose 
            ' Formatter ' : ' verbose ' 
        }, 
    }, 
    # log object 
    ' Loggers ' :
        {
        'Django ' : {
             ' handlers ' : [ ' Console ' , ' File ' ],
             ' Propagate ' : True,   # whether to continue to bubble so the log information to the log processing system of another 
        } 
    } 
}

Configuration logger: utils / logging.py

import logging
logger = logging.getLogger('django')

Guess you like

Origin www.cnblogs.com/zhouze/p/11431696.html