2017 © Pedro Peláez
 

library laravel-error-reporting

Laravel error reporting

image

redfunction/laravel-error-reporting

Laravel error reporting

  • Thursday, April 12, 2018
  • by jtamm
  • Repository
  • 1 Watchers
  • 2 Stars
  • 1,084 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 17 Versions
  • 0 % Grown

The README.md

Laravel error reporting

Install

composer

Direct download

composer require redfunction/laravel-error-reporting

composer.json

{
    "require": {
      "redfunction/laravel-error-reporting" : "*"
    }
}
composer update

ENV (config)

ERROR_REPORTING_EMAIL_FROM=example@example.com
ERROR_REPORTING_EMAIL_FROM_NAME="Example name"
ERROR_REPORTING_EMAIL_RECIPIENTS="example.recipients@example.com second.recipients@example.com"
ERROR_REPORTING_EMAIL_SUBJECT="Test %APP_ENVIRONMENT%"
ERROR_REPORTING_LOG_STACK_TRACE=true
ERROR_REPORTING_JSON_RESPONSE_LONG_MESSAGE=true

config/error.reporting.php

<?php
return array(

    'doNotReportClasses' => [
        Illuminate\Auth\Access\AuthorizationException::class,
        Illuminate\Foundation\Testing\HttpException::class,
        Illuminate\Database\Eloquent\ModelNotFoundException::class,
        Illuminate\Validation\ValidationException::class
    ],
    'doNotReportIpv4Addresses' => [
            '127.0.0.1',
            '192.168.0.0/24'
    ],
    'emailFrom' => env("ERROR_REPORTING_EMAIL_FROM"),
    'emailFromName' => env("ERROR_REPORTING_EMAIL_FROM_NAME"),
    'emailRecipients' => preg_split("/\\s+/", env("ERROR_REPORTING_EMAIL_RECIPIENTS", "")),
    'emailSubject' => env("ERROR_REPORTING_EMAIL_SUBJECT"),
    'emailTemplate' => '',
    'customExceptionRender' => null,
    'logStackTrace' => env("ERROR_REPORTING_LOG_STACK_TRACE", false),
    'jsonResponseLongMessage' => env("ERROR_REPORTING_JSON_RESPONSE_LONG_MESSAGE", false),
    'encryptionAlgorithm' => 'md5',
    'encryptionFields' => [
        'HTTP_AUTHORIZATION',
        [
            'regexPattern' => 'PASSWORD$',
            'useUpperCase'
        ]
    ]
);

If you do not want report excpetion class, then you can add class to array doNotReport. If you want use custom template, then you have to put emailTemplate value., (*1)

Add to plugin to Laravel

You can choice 1) bootstrap/app.php 2) config/app.php, (*2)

bootstrap/app.php

You have to add code., (*3)

$app->singleton(
    Illuminate\Contracts\Debug\ExceptionHandler::class,
    RedFunction\ErrorReporting\ExceptionReportHandler::class
);

config/app.php

You have to add \RedFunction\ErrorReporting\Providers\ExceptionReportProvider::class to providers., (*4)

    'providers' => [
    ...
    \RedFunction\ErrorReporting\Providers\ExceptionReportProvider::class,
    ...
    ]

Example code

Report is working

You have to add implements of class \ErrorReporting\Interfaces\IReportException. Report can call methods (getLogMessage, getLogType, getRedirectPage), (*5)

<?php
/**
 * Class ExceptionUsingReport
 *
 */
class ExceptionUsingReport extends Exception implements RedFunction\ErrorReporting\Interfaces\IReportException
{

    /**
     * @return string
     */
    public function getLogMessage()
    {
        return "Error 500: reason...";
    }

    /**
     * 1 - INFO
     * 2 - WARNING
     * 3 - NOTICE
     * 4 - ERROR
     * @return integer
     */
    public function getLogType()
    {
        return 4;
    }

    /**
     * @return \Illuminate\Routing\Redirector|\Illuminate\Http\RedirectResponse|null
     */
    public function getRedirectPage()
    {
        return null;
    }
}

Report do not send via E-mail.

You have to add trait \ErrorReporting\Exceptions\Traits\DoNotReportToEmail, (*6)

<?php
/**
 * Class ExceptionNotUsingReport
 *
 */
class ExceptionNotUsingReport extends Exception implements RedFunction\ErrorReporting\Interfaces\IReportException
{
    use RedFunction\ErrorReporting\Traits\DoNotReportToEmail;

    /**
     * @return string
     */
    public function getLogMessage()
    {
        return "Error 500: reason...";
    }

    /**
     * 1 - INFO
     * 2 - WARNING
     * 3 - NOTICE
     * 4 - ERROR
     * @return integer
     */
    public function getLogType()
    {
        return 4;
    }

    /**
     * @return \Illuminate\Routing\Redirector|\Illuminate\Http\RedirectResponse|null
     */
    public function getRedirectPage()
    {
        return null;
    }
}

Using custom render

config error.reporting

Example code., (*7)

'customExceptionRender' => [
        'className' => RedFunction\ErrorReporting\Examples\CustomExceptionRender::class,
        'usingException' => [
            RedFunction\ErrorReporting\Examples\ExceptionNotUsingReport::class
        ]
    ]

Create custom render class

<?php
namespace RedFunction\ErrorReporting\Examples;
use Exception;
use Illuminate\Http\Response;
use RedFunction\ErrorReporting\AbstractCustomExceptionRender;


/**
 * Class CustomExceptionRender
 *
 */
class CustomExceptionRender extends AbstractCustomExceptionRender
{
    /**
     * Render an exception into an HTTP response.
     *
     * @param  \Illuminate\Http\Request $request
     * @param  Exception $e
     *
     * @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
     */
    public function render($request, $e)
    {
        //TODO: You can add something, what you want.
        if ($e instanceof Exception) {
            $this->log(self::LOG_NOTICE, $e->getMessage());
            return new Response($e->getMessage(), $e->getCode());
        }
        return null;
    }

    /**
     * AbstractCustomExceptionRender constructor.
     */
    public function __construct()
    {
    }
}

The Versions

12/04 2018

dev-master

9999999-dev https://github.com/redfunction/laravel-error-reporting

Laravel error reporting

  Sources   Download

MIT

The Requires

 

The Development Requires

by Johannes Tamm
by Lauri Elias

plugin laravel email json exception package error reporting report

12/04 2018

0.1.13-beta

0.1.13.0-beta https://github.com/redfunction/laravel-error-reporting

Laravel error reporting

  Sources   Download

MIT

The Requires

 

The Development Requires

by Johannes Tamm
by Lauri Elias

plugin laravel email json package error reporting

03/04 2018

0.1.12-beta

0.1.12.0-beta https://github.com/redfunction/laravel-error-reporting

Laravel error reporting

  Sources   Download

MIT

The Requires

 

The Development Requires

by Johannes Tamm
by Lauri Elias

plugin laravel email json package error reporting

04/09 2017

0.1.11-beta

0.1.11.0-beta https://github.com/redfunction/laravel-error-reporting

Laravel Error reporting

  Sources   Download

MIT

The Requires

 

The Development Requires

by Johannes Tamm

exception error report

08/08 2017

0.1.10-beta

0.1.10.0-beta https://github.com/redfunction/laravel-error-reporting

Laravel Error reporting

  Sources   Download

MIT

The Requires

 

The Development Requires

by Johannes Tamm

exception error report

31/07 2017

0.1.9-beta

0.1.9.0-beta https://github.com/redfunction/laravel-error-reporting

Laravel Error reporting

  Sources   Download

MIT

The Requires

 

The Development Requires

by Johannes Tamm

exception error report

19/06 2017

0.1.8-beta

0.1.8.0-beta https://github.com/redfunction/laravel-error-reporting

Laravel Error reporting

  Sources   Download

MIT

The Requires

 

The Development Requires

by Johannes Tamm

exception error report

19/06 2017

0.1.7-beta

0.1.7.0-beta https://github.com/redfunction/laravel-error-reporting

Laravel Error reporting

  Sources   Download

MIT

The Requires

 

The Development Requires

by Johannes Tamm

exception error report

09/06 2017

0.1.6-beta

0.1.6.0-beta https://github.com/redfunction/laravel-error-reporting

Laravel Error reporting

  Sources   Download

MIT

The Requires

 

The Development Requires

by Johannes Tamm

exception error report

19/05 2017

0.1.5-beta

0.1.5.0-beta https://github.com/redfunction/laravel-error-reporting

Laravel Error reporting

  Sources   Download

MIT

The Requires

 

The Development Requires

by Johannes Tamm

exception error report

13/02 2017

0.1.4-beta

0.1.4.0-beta https://github.com/redfunction/laravel-error-reporting

Laravel Error reporting

  Sources   Download

MIT

The Requires

 

The Development Requires

by Johannes Tamm

exception error report

16/01 2017

0.1.3-beta1

0.1.3.0-beta1 https://github.com/redfunction/laravel-error-reporting

Laravel Error reporting

  Sources   Download

MIT

The Requires

 

The Development Requires

by Johannes Tamm

exception error report

13/01 2017

0.1.3-beta

0.1.3.0-beta https://github.com/redfunction/laravel-error-reporting

Laravel Error reporting

  Sources   Download

MIT

The Requires

 

The Development Requires

by Johannes Tamm

exception error report

05/01 2017

0.1.3

0.1.3.0 https://github.com/redfunction/laravel-error-reporting

Laravel Error reporting

  Sources   Download

MIT

The Requires

 

The Development Requires

by Johannes Tamm

exception error report

20/12 2016

0.1.2

0.1.2.0 https://github.com/redfunction/laravel-error-reporting

Laravel Error reporting

  Sources   Download

MIT

The Requires

 

The Development Requires

by Johannes Tamm

exception error report

09/12 2016

0.1.1

0.1.1.0 https://github.com/redfunction/laravel-error-reporting

Laravel Error reporting

  Sources   Download

MIT

The Requires

 

The Development Requires

by Johannes Tamm

exception error report

07/12 2016

0.1

0.1.0.0

Laravel Error reporting

  Sources   Download

proprietary

The Requires

 

The Development Requires