| 1 |
idlErrorManagementPlugin |
|---|
| 2 |
======================== |
|---|
| 3 |
|
|---|
| 4 |
This plugin provides a set of functionnalities to handle errors in production environement. The current functionalities are: |
|---|
| 5 |
|
|---|
| 6 |
* Possibility to record Exceptions in the database |
|---|
| 7 |
* Possibility to Record php fatal error in the database |
|---|
| 8 |
* Allow users to add comments to recorded errors/exceptions |
|---|
| 9 |
* Browse the recorded exceptions/errors through an admin module |
|---|
| 10 |
* Convert 404 exceptions to standards errors |
|---|
| 11 |
* Sending of emails when the errors occur or when a user add a comment to it |
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
Installation |
|---|
| 15 |
------------ |
|---|
| 16 |
|
|---|
| 17 |
By using the PEAR package: |
|---|
| 18 |
|
|---|
| 19 |
$ symfony plugin:install idlDoctrineMigrationPlugin |
|---|
| 20 |
|
|---|
| 21 |
Or by downloading the code, or adding an svn:externlas and active the plugin in our ProjectConfiguration.class.php, adding these lines: |
|---|
| 22 |
``` |
|---|
| 23 |
public function setup() { |
|---|
| 24 |
parent::setup(); |
|---|
| 25 |
$this->enablePlugins('idlErrorManagementPlugin'); |
|---|
| 26 |
} |
|---|
| 27 |
``` |
|---|
| 28 |
|
|---|
| 29 |
By default the plugin does nothing. You must activate the functionalities one by one. Here the detail, of how it works and how to setup each functionality: |
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
Record Exception to database |
|---|
| 33 |
---------------------------- |
|---|
| 34 |
|
|---|
| 35 |
To start this functionnality, add the following config in your app.yml: |
|---|
| 36 |
|
|---|
| 37 |
all: |
|---|
| 38 |
error_management: |
|---|
| 39 |
record_exception_to_db: true |
|---|
| 40 |
|
|---|
| 41 |
After this, symfony will notify the plugin each time an exception occurs. The plugin will then record the Exception details and let symfony continue with the standard exception handling mecanism. So this is transparent for the user, but you will get advanced logging in the database. |
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
Record php fatal errors in database |
|---|
| 45 |
---------------------------------- |
|---|
| 46 |
|
|---|
| 47 |
This is an interesting feature. It is really painful when we get "php fatal error" that completly broke the script... |
|---|
| 48 |
With this you will be at able to identify thoses problems and try to fix them. To activate it: |
|---|
| 49 |
|
|---|
| 50 |
all: |
|---|
| 51 |
error_management: |
|---|
| 52 |
record_php_error: true |
|---|
| 53 |
|
|---|
| 54 |
Once you have started this functionality, a small php script will be created in the cache and registered in the php engine with register_shutdown_function() so that the plugin will be able to log the fatal error to the database just before ending. |
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
Allow users to comment an error |
|---|
| 58 |
------------------------------ |
|---|
| 59 |
|
|---|
| 60 |
This functionality that may not be so useful on a website, but can be very interresting for complex web applications. To activate it, add this in your app.yml: |
|---|
| 61 |
|
|---|
| 62 |
all: |
|---|
| 63 |
error_management: |
|---|
| 64 |
ask_user_to_comment: true |
|---|
| 65 |
after_comment_route: @homepage |
|---|
| 66 |
|
|---|
| 67 |
Then, every time an error is recorded in the database, the user is redirected to a specific page allowing him to add a comment about the error and the severity of the problem. This two informations are then attached to the errors. |
|---|
| 68 |
By default, once the comment have been posted, the user is redirected to @homepage, this can be overhide with the ``after_comment_route`` parameter |
|---|
| 69 |
|
|---|
| 70 |
WARNING, As this module is translatable, I18N should be activate. If you are not using I18N, you can use the module by overhiding the template comment ``modules/idlCommentApplicationError/templates/commentLastErrorSuccess.php`` |
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
Browse the recorded exception/errors through an admin module |
|---|
| 74 |
------------------------------------------------------------ |
|---|
| 75 |
|
|---|
| 76 |
To use the module, you just need to activate it in the setting.yml of the application of your choice. |
|---|
| 77 |
You will be able to browse every errors recorded... |
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
Convert 404 exception to standard error |
|---|
| 81 |
--------------------------------------- |
|---|
| 82 |
|
|---|
| 83 |
Sometimes, 404 errors should not occur, in this case, maybe you want the same error management than any other errors. |
|---|
| 84 |
This action allows to convert any error 404 to a standard ApplicationError. To use it, just configure the setting.yml with |
|---|
| 85 |
|
|---|
| 86 |
.settings |
|---|
| 87 |
error_404_module: idlErrorManagementTools # To be called when a 404 error is raised |
|---|
| 88 |
error_404_action: convert404ToApplicationError # Or when the requested URL doesn't match any route |
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 |
Sending emails |
|---|
| 92 |
-------------- |
|---|
| 93 |
|
|---|
| 94 |
You can configure the plugin to automatically send emails. Here is the config params: |
|---|
| 95 |
|
|---|
| 96 |
all: |
|---|
| 97 |
error_management: |
|---|
| 98 |
send_mail_on_error: false # To send an email when the error occurs |
|---|
| 99 |
send_mail_on_user_comment: false # To send an email when a user comment an error |
|---|
| 100 |
email_to: info@example.com |
|---|
| 101 |
email_from: info@example.com |
|---|
| 102 |
|
|---|
| 103 |
This part of the plugin use the native mailer of symfony, so you have to configure it in factories.yml. For more information, check here: |
|---|
| 104 |
http://www.symfony-project.org/reference/1_4/en/05-Factories#chapter_05_mailer |
|---|
| 105 |
|
|---|
| 106 |
With this, you can get live notification of when your application runs in troubles... |
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 |
Evolution |
|---|
| 110 |
--------- |
|---|
| 111 |
|
|---|
| 112 |
List of functionnality missing or to improved: |
|---|
| 113 |
|
|---|
| 114 |
* Find a way to generate the redirect even when it's a php fatal error |
|---|
| 115 |
* Finalize the admin module, specially add a show error page |
|---|
| 116 |
|
|---|
| 117 |
|
|---|