|
| 1 | +NelmioJsLoggerBundle |
| 2 | +==================== |
| 3 | + |
| 4 | +The **NelmioJsLoggerBundle** bundle allows you to log errors happening in the frontend. |
| 5 | + |
| 6 | +## Installation ## |
| 7 | + |
| 8 | +Add this bundle to your `composer.json` file: |
| 9 | + |
| 10 | + { |
| 11 | + "require": { |
| 12 | + "nelmio/js-logger-bundle": "dev-master" |
| 13 | + } |
| 14 | + } |
| 15 | + |
| 16 | +Register the bundle in `app/AppKernel.php`: |
| 17 | + |
| 18 | + // app/AppKernel.php |
| 19 | + public function registerBundles() |
| 20 | + { |
| 21 | + return array( |
| 22 | + // ... |
| 23 | + new Nelmio\JsLoggerBundle\NelmioJsLoggerBundle(), |
| 24 | + ); |
| 25 | + } |
| 26 | + |
| 27 | +Import the bundle's routing definition in `app/config/routing.yml`: |
| 28 | + |
| 29 | + # app/config/routing.yml |
| 30 | + NelmioJsLoggerBundle: |
| 31 | + resource: "@NelmioJsLoggerBundle/Resources/config/routing.xml" |
| 32 | + prefix: /nelmio-js-logger |
| 33 | + |
| 34 | +## Automated Error Logging ## |
| 35 | + |
| 36 | +The bundle exposes two twig functions that you should put in your site template somewhere. |
| 37 | + |
| 38 | +To enable automatic logging of javascript errors, use `nelmio_js_error_logger()`: |
| 39 | + |
| 40 | + {{ nelmio_js_error_logger() }} |
| 41 | + |
| 42 | +You can optionally change the level (default is ERROR) and remove the surrounding `<script>..</script>` tags: |
| 43 | + |
| 44 | + {{ nelmio_js_error_logger('WARNING', false) }} |
| 45 | + |
| 46 | +## Manual Logging from JavaScript ## |
| 47 | + |
| 48 | +To expose the `log()` function to your JS code, use `nelmio_js_logger()`: |
| 49 | + |
| 50 | + {{ nelmio_js_logger() }} |
| 51 | + |
| 52 | +You can also change the function name if `log` is too generic for you: |
| 53 | + |
| 54 | + {{ nelmio_js_logger('my_log_function') }} |
| 55 | + |
| 56 | +The function signature is as such: `log(level, message, context)`. The level and |
| 57 | +message are mandatory. The context is a data object that can contain any additional |
| 58 | +details you want to store. |
| 59 | + |
| 60 | +## Configuration ## |
| 61 | + |
| 62 | +You can restrict the logging levels accessible from javascript. The point |
| 63 | +is that if some of your logging levels email you or notify you in some way, |
| 64 | +you probably do not want to allow anyone to send requests and wake you up |
| 65 | +at 2AM. |
| 66 | + |
| 67 | +Here is the default configuration that exposes all levels: |
| 68 | + |
| 69 | + # app/config/config.yml |
| 70 | + nelmio_js_logger: |
| 71 | + allowed_levels: ['DEBUG', 'INFO', 'NOTICE', 'WARNING', 'ERROR', 'CRITICAL', 'ALERT', 'EMERGENCY'] |
0 commit comments