​​
The @app.errorhandler decorated method is called in the context of an
exception, so you can use app.logger.exception to log a message and the
original exception with traceback:

import loggingimport sys
import flaskimport werkzeug.exceptions

handler = logging.StreamHandler(stream=sys.stderr)

app = flask.Flask(__name__)
app.logger.addHandler(handler)
@app.route('/')def get():
    raise Exception('oh noes')
    return 'hello'
@app.errorhandler(Exception)def handle_error(exc):
    app.logger.exception('Unhandled Exception')
    return werkzeug.exceptions.InternalServerError()

app.run()

 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
Unhandled Exception
Traceback (most recent call last):
  File 
"/Users/jstewmon/.virtualenvs/harp/lib/python2.7/site-packages/flask/app.py",
line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File 
"/Users/jstewmon/.virtualenvs/harp/lib/python2.7/site-packages/flask/app.py",
line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File 
"/Users/jstewmon/Library/Preferences/IntelliJIdea2016.2/scratches/scratch_14.py",
line 17, in get
    raise Exception('oh noes')
Exception: oh noes
127.0.0.1 - - [22/Aug/2016 21:51:51] "GET / HTTP/1.1" 500 -

​

On Mon, Aug 22, 2016 at 7:47 PM, jack phelan <jackp...@gmail.com> wrote:

> if I have
>
>     @app.errorhandler(Exception)
>     def all_exception_handler(error):
>         app.logger.error(error)
>         return 'Error', 500
>
> then https://github.com/pallets/flask/blob/master/flask/app.py#L1515 will
> invoke my handler with only exc_value.
> So if I want line numbers or traceback I have to let reraise get called?
>
> --
> You received this message because you are subscribed to the Google Groups
> "pocoo-libs" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to pocoo-libs+unsubscr...@googlegroups.com.
> To post to this group, send email to pocoo-libs@googlegroups.com.
> Visit this group at https://groups.google.com/group/pocoo-libs.
> For more options, visit https://groups.google.com/d/optout.
>

-- 

This e-mail, including attachments, contains confidential and/or 
proprietary information, and may be used only by the person or entity to 
which it is addressed. The reader is hereby notified that any 
dissemination, distribution or copying of this e-mail is prohibited. If you 
have received this e-mail in error, please notify the sender by replying to 
this message and delete this e-mail immediately.

-- 
You received this message because you are subscribed to the Google Groups 
"pocoo-libs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to pocoo-libs+unsubscr...@googlegroups.com.
To post to this group, send email to pocoo-libs@googlegroups.com.
Visit this group at https://groups.google.com/group/pocoo-libs.
For more options, visit https://groups.google.com/d/optout.

Reply via email to