承接 onlime/exception-report-bundle 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

onlime/exception-report-bundle

Composer 安装命令:

composer require onlime/exception-report-bundle

包简介

Enables simple exception reports by email in your Symfony3 project.

README 文档

README

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.

This bundle was inspired by PhpAirbrakeBundle.

Requirements

Installation

Install with Composer

$ composer require onlime/exception-report-bundle

Update GeoIP database:

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

Configuration

Enable bundle in your AppKernel.php:

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

Configure bundle in config.yml:

# 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:

# 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:

$ bin/console config:dump-reference onlime_exception_report

Sample Report

Simply throw an exception in one of your controllers, e.g.:

<?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:

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:

<?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)

License

This bundle is released under the MIT license.

Credits

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

I would also like to thank Mike Meier for his advice.

统计信息

  • 总下载量: 79
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-02-28

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固