推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
NeverBelieveMe
V2EX  ›  Python

log 使用方式错误,求指导

  •  
  •   NeverBelieveMe · Feb 26, 2020 · 1630 views
    This topic created in 2280 days ago, the information mentioned may be changed or developed.
    A.py
    logger = logging.getLogger(__name__)
    logger.setLevel(logging.DEBUG)
    handler = logging.StreamHandler()
    handler.setFormatter(logging.Formatter("%(asctime)s - %(message)s"))
    logging.getLogger().addHandler(handler)


    B.py
    from A import logger
    C.py
    from A import logger

    我现在在项目中是这样使用的。之前的帖子里有人说不能这样重复引用,单独用 logger = logging.getLogger(__name__)。但是这样,logger 就需要重新配置了。所以不清楚怎么用是对的。
    gwy15
        1
    gwy15  
       Feb 26, 2020   ❤️ 1
    单独 logging.getLogger(__name__) 是对的,因为包名存在前缀,所以配置根 logger 就可以了( propagate=True )
    NeverBelieveMe
        2
    NeverBelieveMe  
    OP
       Feb 26, 2020
    @gwy15 明白了,谢谢
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   6026 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 58ms · UTC 02:58 · PVG 10:58 · LAX 19:58 · JFK 22:58
    ♥ Do have faith in what you're doing.