Python-requests中, 这一段logging的用法是什么作用 ?
天蓬老师
天蓬老师 2017-04-18 10:23:03
0
1
527

实际现象

  • 一段不熟悉的logging用法( 猜测是给库打log 用的 )

预期现象

  • 弄清楚该段 logging 代码的作用原理( 虽然有句注释 # Set default logging handler to avoid "No handler found" warnings. )

相关代码

  • requests.__init__.py中的用法

# Set default logging handler to avoid "No handler found" warnings.
import logging
try:  # Python 2.7+
    from logging import NullHandler
except ImportError:
    class NullHandler(logging.Handler):
        def emit(self, record):
            pass

logging.getLogger(__name__).addHandler(NullHandler())

上下文环境

  • 产品版本: requests最新

  • 操作系统: Linux

  • Python: 2.7.x

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

모든 응답(1)
左手右手慢动作

즉, 현재 버전의 로깅 모듈에 NullHandler가 없으면 직접 작성하고 후속 코드에 NullHandler를 사용할 수 있는지 확인하세요.

최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!