2017 © Pedro Peláez
 

symfony-bundle exception-report-bundle

Enables simple exception reports by email in your Symfony3 project.

image

onlime/exception-report-bundle

Enables simple exception reports by email in your Symfony3 project.

  • Tuesday, December 27, 2016
  • by onlime
  • Repository
  • 1 Watchers
  • 0 Stars
  • 50 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 8 Versions
  • 0 % Grown

The README.md

Symfony3 Exception Report Bundle

This bundle will autoload an exception handler into the framework, so that all uncaught errors are sent by email to the developer. No external services required. Just produces bloody simple exception reports including important client and request metadata., (*1)

This bundle was inspired by PhpAirbrakeBundle., (*2)

Requirements

Installation

Install with Composer

$ composer require onlime/exception-report-bundle

Update GeoIP database:, (*3)

$ bin/console maxmind:geoip:update-data http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz

Configuration

Enable bundle in your AppKernel.php:, (*4)

# app/AppKernel.php
<?php
    // ...
    public function registerBundles()
    {
        $bundles = array(
            // ...
            new Onlime\ExceptionReportBundle\OnlimeExceptionReportBundle(),
        );
    }

Configure bundle in config.yml:, (*5)

# app/config/config.yml

onlime_exception_report:
    handlers:
        swift:
            # by default 4xx http exceptions are not reported:
            # exclude_http: true
            #
            # to also log 4xx level errors (but not 404's):
            # exclude_http: false
            # excluded_404s:
            #     - ^/
            #
            # to hide stacktrace output for specific exceptions,
            # add them with fully qualified class name:
            # no_stacktrace_on_exceptions:
            #     - Doctrine\DBAL\Exception\ConnectionException
            #     - PDOException
            #
            exclude_http: false
            from_email: '%email.admin%'
            to_email:   '%email.admin%'
            subject:    "[Example.com] Exception Report"

You might disable specific handlers on dev environment:, (*6)

# app/config/config_dev.yml

onlime_exception_report:
    handlers:
        swift:
            enabled: false

Default configuration reference

# Default configuration for extension with alias: "onlime_exception_report"
onlime_exception_report:
    handlers:

        # Prototype
        name:
            enabled:              true
            exclude_http:         true
            excluded_404s:        []
            no_stacktrace_on_exceptions:  []
            from_email:           ~ # Required
            to_email:             [] # Required
            subject:              'Exception Report'

This default configuration reference was generated with the following command:, (*7)

$ bin/console config:dump-reference onlime_exception_report

Sample Report

Simply throw an exception in one of your controllers, e.g.:, (*8)

<?php

namespace AppBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

/**
 * @Route("/demo")
 */
class DemoController extends Controller
{
    /**
     * Simply throws an Exception to test exception reporting.
     *
     * @Route("/exception", name="demo_exception")
     */
    public function exceptionAction()
    {
        throw new \Exception('Something really bad happened!');
    }
}

You will then find the exception report in the web debug toolbar or (on a correctly configured Swift mailer) in your mailbox:, (*9)

GET /demo/exception: Something really bad happened!
Exception: Exception

Date:       Sun, 28 Feb 2016 22:15:47 +0100
ClientIP:   212.51.128.110 (CH / Switzerland)
ClientHost: 212-51-128-110.fiber7.init7.net
ReqHost:    demo.example.com
ReqUri:     http://demo.example.com/demo/exception
Env:        prod
Route:      demo_exception
User:       onlime
Agent:      Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:49.0) Gecko/20100101 Firefox/49.0
Referer:

------------------------------------------------------------
Stack trace
------------------------------------------------------------
#0 [internal function]: AppBundle\Controller\DemoController->exceptionAction()
#1 vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php(139): call_user_func_array(Array, Array)
#2 vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php(62): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#3 vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php(169): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#4 web/app.php(58): Symfony\Component\HttpKernel\Kernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#5 {main}

------------------------------------------------------------
Request Parameters
------------------------------------------------------------

POST Array
(
)


GET Array
(
)

Special Use Cases

Trigger Exception report without breaking application

Let's say you have caught an exception (e.g. from an API request) and do not wish to break the application flow, but still want to report the complete exception. That's what the ExceptionEvent is for - simply trigger it in your controller like this:, (*10)

<?php
use Onlime\ExceptionReportBundle\Event\ExceptionEvent;
use Onlime\ExceptionReportBundle\Event\ExceptionEvents;

// ...

        try {
            // do some dangerous stuff here...
        } catch (\Exception $e) {
            $this->get('event_dispatcher')->dispatch(
                ExceptionEvents::REPORT,
                new ExceptionEvent($e)
            );
        }

Authors

Copyright (c) 2016 Onlime Webhosting www.onlime.ch (Twitter @ondalime), (*11)

License

This bundle is released under the MIT license., (*12)

Credits

This bundle is both inspired by and is using some of the code from ibrows/PhpAirbrakeBundle which is a fork of dbtlr/PhpAirbrakeBundle., (*13)

I would also like to thank [Mike Meier][8] for his advice., (*14)

The Versions

27/12 2016

dev-master

9999999-dev https://www.onlime.ch/

Enables simple exception reports by email in your Symfony3 project.

  Sources   Download

MIT

The Requires

 

logging bundle symfony3 exceptions error handling onlime

10/05 2016
15/04 2016

0.3.4

0.3.4.0 https://www.onlime.ch/

Enables simple exception reports by email in your Symfony3 project.

  Sources   Download

MIT

The Requires

 

logging bundle symfony3 exceptions error handling onlime

05/04 2016

0.3.3

0.3.3.0 https://www.onlime.ch/

Enables simple exception reports by email in your Symfony3 project.

  Sources   Download

MIT

The Requires

 

logging bundle symfony3 exceptions error handling onlime

28/03 2016

0.3.2

0.3.2.0 https://www.onlime.ch/

Enables simple exception reports by email in your Symfony3 project.

  Sources   Download

MIT

The Requires

 

logging bundle symfony3 exceptions error handling onlime

01/03 2016

0.3.1

0.3.1.0 https://www.onlime.ch/

Enables simple exception reports by email in your Symfony3 project.

  Sources   Download

MIT

The Requires

 

logging bundle symfony3 exceptions error handling onlime

29/02 2016