1
我想在Python 3這種方式增加日誌處理程序:爲什麼我的日誌記錄在Python 3中不起作用?
$ python3
Python 3.5.2 (default, Sep 14 2017, 22:51:06)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import logging
>>>
>>> logger = logging.getLogger()
>>> handler = logging.StreamHandler()
>>> handler.setLevel(logging.INFO)
>>> logger.addHandler(handler)
>>>
>>> logging.info("my info")
>>> logging.warning("my warning")
my warning
我指定的記錄等級爲INFO
。爲什麼logging.info("my info")
不輸出?
如果你只是想記錄到一個單一的處理程序,您可以使用['logging.basicConfig'](https://docs.python.org/3/library /logging.html#logging.basicConfig) – Holloway