Feature summary:
Python logging.exception() uses exc_info=True by default [1] which means the traceback is shown whereas Pywikibot pywikibot.logging.exception() (also available as pywikibot.exception()) uses tb=False by default. There is not significant difference between pywikibot.exception() and pywkibot.error() except that the pywikibot variant of exception is able to get the exception from sys.exc_info() and the msg parameter may be omitted.
The behaviour of pywikibot.exception() should be in sync with the underlying Python implementation and the tb parameter should be True by default.
Use case(s):
Currently there is no difference between pywikibot.error() and pywikibot.exception() if the exception is given as message:
import pywikibot
try:
1/0
except Exception as e:
pywikibot.error(e)
ERROR: division by zero
try:
1/0
except Exception as e:
pywikibot.error(e, exc_info=True)
ERROR: division by zero
Traceback (most recent call last):
File "<pyshell#7>", line 2, in <module>
ZeroDivisionError: division by zerotry:
1/0
except Exception as e:
pywikibot.exception(e)
ERROR: division by zero
try:
1/0
except Exception as e:
pywikibot.exception(e, tb=True)
ERROR: division by zero
Traceback (most recent call last):
File "<pyshell#11>", line 2, in <module>
ZeroDivisionError: division by zero
try:
1/0
except Exception as e:
pywikibot.exception(e, exc_info=True)
ERROR: division by zero
Traceback (most recent call last):
File "<pyshell#13>", line 2, in <module>
ZeroDivisionError: division by zeroBenefits:
The behaviour for pywikibot.error() should be differ from pywikibot.exception() and follow the underlying Python implementation..
I propose to change this behaviour with Pywikibot 8 because ist is a breaking change but I don't see any important impact to have a longer deprecation period here.
[1] https://docs.python.org/3/library/logging.html#logging.exception