For example, this bit of code below works as expected:
import logging
import sys
def infologAllUncaught(exc_type, exc_value, exc_traceback):
logging.error("Uncaught exception", exc_info=(exc_type, exc_value, exc_traceback))
sys.excepthook = infologAllUncaught
raise Exception("WOAH THERE!")
returning:
ERROR:root:Uncaught exception
Traceback (most recent call last):
File "C:\dev\proj\cedu_ui\product\trunk\test\tools\genie\genie\logging_test2.py", line 9, in <module>
raise Exception("WOAH THERE!")
Exception: WOAH THERE!
However, this bit of code returns nothing.
import logging
import sys
def infologAllUncaught(exc_type, exc_value, exc_traceback):
logging.info("Uncaught exception", exc_info=(exc_type, exc_value, exc_traceback))
sys.excepthook = infologAllUncaught
raise Exception("WOAH THERE!")
It seems like all the logging methods except logging.exception have the same usage in the API, so I'm not sure why these are yielding different results.
You probably need to configure your logger to log at INFO level, the default is only WARNING.
Ref: docs.python.org/2/howto/logging.html#when-to-use-logging "The default level is WARNING ..."
You might want to look at using something like this https://docs.python.org/2/howto/logging.html#logging-to-a-file to do the initial logger configuration.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.