Error Handling documentation fixes (grammar, etc)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Adam Zapletal · committed by Armin Ronacher · parent 505c530 · Browse files · 1 file·+17 added−16 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+17 added−16 removed
- other:+17 added−16 removed
Provenance
- Commit
ee5eafa- Tree
7b4a24b- Author
Adam Zapletal <adamzap@gmail.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
505c530
1 file changed+17 added−16 removed
modified:docs/errorhandling.rst+17 added-16 removed
3 unmodified lines4 ===========================5 6 .. versionadded:: 0.37 8-Applications fail, server fail. Sooner or later you will see an exception8+Applications fail, servers fail. Sooner or later you will see an exception9 in production. Even if your code is 100% correct, you will still see10 exceptions from time to time. Why? Because everything else involved will11 fail. Here some situations where perfectly fine code can lead to server12 errors:6 unmodified lines19 - a backend server overloaded20 - a programming error in a library you are using21 - network connection of the server to another system failed.22 23-And that's just a small sample of issues you could be facing. So how to23+And that's just a small sample of issues you could be facing. So how do we24 deal with that sort of problem? By default if your application runs in25 production mode, Flask will display a very simple page for you and log the26 exception to the :attr:`~flask.Flask.logger`.27 3 unmodified lines31 Error Mails32 -----------33 34 If the application runs in production mode (which it will do on your35-server) you won't see any log messages by default. Why that? Flask tries36-to be a zero-configuration framework and where should it drop the logs for37-you if there is no configuration. Guessing is not a good idea because38-chances are, the place it guessed is not the place where the user has the35+server) you won't see any log messages by default. Why is that? Flask36+tries to be a zero-configuration framework. Where should it drop the logs37+for you if there is no configuration? Guessing is not a good idea because38+chances are, the place it guessed is not the place where the user has39 permission to create a logfile. Also, for most small applications nobody40 will look at the logs anyways.41 42 In fact, I promise you right now that if you configure a logfile for the1 unmodified line44 when a user reported it for you. What you want instead is a mail the45 second the exception happened. Then you get an alert and you can do46 something about it.47 48-Flask is using the Python builtin logging system and that one can actually49-send you mails for errors which is probably what you want. Here is how50-you can configure the Flask logger to send you mails for exceptions::48+Flask uses the Python builtin logging system, and it can actually send49+you mails for errors which is probably what you want. Here is how you can50+configure the Flask logger to send you mails for exceptions::51 52 ADMINS = ['yourname@example.com']53 if not app.debug:54 import logging7 unmodified lines62 So what just happened? We created a new63 :class:`~logging.handlers.SMTPHandler` that will send mails with the mail64 server listening on ``127.0.0.1`` to all the `ADMINS` from the address65 *server-error@example.com* with the subject "YourApplication Failed". If66-your mail server requires credentials these can also provided, for that67-check out the documentation for the :class:`~logging.handlers.SMTPHandler`.66+your mail server requires credentials, these can also be provided. For67+that check out the documentation for the68+:class:`~logging.handlers.SMTPHandler`.69 70 We also tell the handler to only send errors and more critical messages.71 Because we certainly don't want to get a mail for warnings or other72 useless logs that might happen during request handling.42 unmodified lines115 Controlling the Log Format116 --------------------------117 118 By default a handler will only write the message string into a file or118-send you that message as mail. But a log record stores more information119+send you that message as mail. A log record stores more information,120 and it makes a lot of sense to configure your logger to also contain that121 information so that you have a better idea of why that error happened, and122 more importantly, where it did.123 123-A formatter can be instanciated with a format string. Note that124+A formatter can be instantiated with a format string. Note that125 tracebacks are appended to the log entry automatically. You don't have to126 do that in the log formatter format string.127 128 Here some example setups:77 unmodified lines206 :meth:`~logging.Formatter.formatTime`:207 called for `asctime` formatting. If you want a different time format208 you can override this method.209 :meth:`~logging.Formatter.formatException`209- called for exception formatting. It is passed a :attr:`~sys.exc_info`210+ called for exception formatting. It is passed an :attr:`~sys.exc_info`211 tuple and has to return a string. The default is usually fine, you212 don't have to override it.213 214 For more information, head over to the official documentation.2 unmodified lines217 Other Libraries218 ---------------219 220 So far we only configured the logger your application created itself.220-Other libraries might log themselves as well. For example, SQLAlchemy use221-logging heavily in the core. While there is a method to configure all221+Other libraries might log themselves as well. For example, SQLAlchemy uses222+logging heavily in its core. While there is a method to configure all223 loggers at once in the :mod:`logging` package, I would not recommend using224 it. There might be a situation in which you want to have multiple225 separate applications running side by side in the same Python interpreter226 and then it becomes impossible to have different logging setups for those.11 unmodified lines