Closed chen19901225 closed 6 years ago
Thanks for reporting this bug and for the code sample!
You can fix this by adding better_exceptions.patch_logging()
at the top of your main()
or ping()
function (but prefer a place where it will be called only once). :wink:
Technical explanation follows.
So, tornado
reports exceptions through the logging
system. better_exceptions
does patch the loggers to format the errors on the fly, it does so by modifying existing handlers and by setting the _defaultFormatter
of the logging
module to a custom one.
However, while creating a root handler, the basicConfig()
function (used by tornardo
) of the logging
module makes directly use of the Formatter
class rather than the default one.
As a result, if you import and hook better_exceptions
before calling basicConfig()
, the root logger will be configured with a non-patched formatter. Calling .hook()
after basicConfig()
should fix it, but this can't be done easily here as the tornardo
logger configuration is delayed. Also, it worth noting that calling getLogger("some.submodule")
may force a call to _fixupParents()
with the side-effect of patching the existing handlers.
It is quite unfortunate that better_exceptions
does not effectively patch delayed logger created with basicConfig()
, but for now I do not know how to fix it without introducing ugly mocking.
@Delgan thanks
env:
"sys": "win10", "python: "python3.6.5", "tornado": "5.0.2", "better-excpetions": "0.2.1"
demo
outuput