Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support logging #21

Closed
ulope opened this issue Mar 24, 2017 · 4 comments
Closed

Support logging #21

ulope opened this issue Mar 24, 2017 · 4 comments

Comments

@ulope
Copy link

ulope commented Mar 24, 2017

Python's logging module has the ability to output tracebacks alongside log messages if inside an exception context (Logger.<level_method>(..., exc_info=True) and Logger.exception(...)).

It would be great if better exceptions could also inject it's enhanced traceback rendering there.

@Qix-
Copy link
Owner

Qix- commented Mar 24, 2017

Sure! I'll take a look later today.

@Qix-
Copy link
Owner

Qix- commented Mar 28, 2017

Can you test the latest master? :)

@nilleb
Copy link

nilleb commented Mar 29, 2017

Doesn't work for me.

  1. isatty (in colors.py) can throw OSError (on some exotic environments like GAE)
  2. more to come (the format_exception is not being called, I still don't know why. I am using a custom logging.Formatter, this is possibly the reason for which it doesn't work)

@Qix-
Copy link
Owner

Qix- commented Mar 29, 2017

  1. Good to know, I didn't realize it would throw on certain platforms. I'll fix that.
  2. Right, custom formatters will need to handle it and call format_exception themselves. The only logger formatter that I override is the default StreamHandler's formatter on Python 2.7 and _StderrHandler on Python 3.x. I didn't want to be too intrusive seeing as how I didn't want to change how existing programs worked if they had very specific requirements from their logging formatters.

However, if you add format_exception to your custom formatter, you'll need a lambda:

from better_exceptions import format_exception
my_formatter.formatException = lambda exc_info: format_exception(*exc_info)

I haven't decided on the API yet since it appears the formatter function for exceptions is one of the few places in the standard Python API that accepts the typical triple of exc_info values as a triple instead of three unpacked arguments.

So either I break the API convention in better_exceptions and have format_exception accept a triple, or I require that you use a lambda to expand the arguments and keep format_exception as the three-argument version.

If you have thoughts on how to approach custom formatters and the like, let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants