配置日志系统
Posted djfboai
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了配置日志系统相关的知识,希望对你有一定的参考价值。
配置setting
LOGGING = { ‘version‘: 1, ‘disable_existing_loggers‘: True, ‘formatters‘:{ "generic": { "format": "%(asctime)s [%(process)d] [%(levelname)s] %(message)s", "datefmt": "[%Y-%m-%d %H:%M:%S %z]", "class": "logging.Formatter" }, "access": { "format": "%(message)s", "class": "logging.Formatter" } }, ‘loggers‘: { "AuthCert.error": { "level": "INFO", "handlers": ["error_file"], "propagate": 1, "qualname": "AuthCert.error" }, "AuthCert.access": { "level": "INFO", "handlers": ["access_file"], "propagate": 0, "qualname": "AuthCert.access" } }, ‘handlers‘: { "console": { "class": "logging.StreamHandler", "formatter": "generic", "stream": "sys.stdout" }, "error_file": { "class": "logging.FileHandler", "formatter": "generic", "filename": "./log/error.log" }, "access_file": { "class": "logging.handlers.RotatingFileHandler", "maxBytes": 1024 * 1024, "backupCount": 5, "formatter": "generic", "filename": "./log/acess.log", } }, }
配置函数
import logging logger = logging.getLogger(‘AuthCert.error‘)
写日志
logger.info(‘增加用户成功‘) logger.info(‘success‘)
效果
error可以看见所有的日志信息
以上是关于配置日志系统的主要内容,如果未能解决你的问题,请参考以下文章
我的Android进阶之旅NDK开发之在C++代码中使用Android Log打印日志,打印出C++的函数耗时以及代码片段耗时详情