Django configuration using log

A. Django used log

  Django used log is actually very simple, just need to (if not custom, it is in settings.py) to add the following settings, and can be modified according to their needs in a configuration file used in the project:

# 官网: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': {
            # 实际开发建议使用WARNING
            'level': 'INFO',
            'class': 'logging.handlers.RotatingFileHandler',
            #Log location, log file name, the log save directory must be manually created, and then to the corresponding path can Note: This file path should pay attention to base_dir 
            ' filename ' : os.path.join (os.path.dirname (base_dir), " logs / manage.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 ' ,
             # set the log encoding 
            ' encoding ' : '. 8-UTF ' 
        }, 
    }, 
    # log object 
    ' Loggers ' : {
         ' Django ' : {
             ' handlers ' : [ ' Console ' , ' File ' ],
             ' Propagate ' : True,   # whether to allow the log information continues to bubble other log processing system 
        }, 
    } 
}

 

Guess you like

Origin www.cnblogs.com/maoruqiang/p/11246906.html