django日志配置

直接参考这篇,很详细:https://www.cnblogs.com/changqing8023/p/9639769.html

补充一点:日志文件打开时,中文乱码,要在handler中设置编码格式,'encoding': 'utf-8'

'default': {
            'level': 'INFO',
            # handlers.RotatingFileHandler 将日志消息写入文件filename,如果文件的大小超出maxBytes制定的值,那么它将被备份为filename1
            'class': 'logging.handlers.RotatingFileHandler',
            # all.log 输入系统日志,info日志和error日志
            'filename': os.path.join(log_path, 'all-{}.log'.format(time.strftime('%Y_%m_%d'))),
            'maxBytes': 1024 * 1024 * 5,  # 文件大小
            'backupCount': 5,  # 备份数
            'formatter': 'standard',  # 输出格式
            'encoding': 'utf-8',  # 设置默认编码
        },
原文地址:https://www.cnblogs.com/dannyyao/p/10212722.html