Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

LERN is a Laravel 5 package that will record exceptions into a database and will notify you via Email, Pushover or Slack.

License

NotificationsYou must be signed in to change notification settings

tylercd100/lern

Repository files navigation

Latest VersionSoftware LicenseBuild StatusScrutinizer Code QualityCode CoverageTotal Downloads

LERN from your mistakes

LERN is a Laravel 5 package that will record exceptions into a database and will send you a notification.

Currently supported notification channels viaMonolog

Version Compatibility

LaravelLERN
5.1.x3.x
5.2.x3.x
5.3.x3.x
5.4.x3.x
5.5.x4.x
5.6.x4.x
6.x5.x and 6.x
7.x6.x
8.x6.x

Migrating from3.x to4.x

Make sure that the config file now includes the newlern.notify.class andlern.record.class settings. Check theconfig file to see how they are used.

Migrating from2.x to3.x

Version 3.x introduces the ability to collect more information from the error such as the user_id, url, method, and input data. In order to use 3.x you will need to copy over the newconfig file, the migration file and then migrate it.

# This will only copy over the migration file. For the config file you can either include the --force flag (Which will overwrite it) or copy it manually from githubphp artisan vendor:publish --provider="Tylercd100\LERN\LERNServiceProvider"php artisanmigrate

Installation

Version 4.x usesPackage Discovery. If you are using 3.x you will need to follow theseinstructions.

Install viacomposer - In the terminal:

composer require tylercd100/lern

Then you will need to run these commands in the terminal in order to copy the config and migration files

php artisan vendor:publish --provider="Tylercd100\LERN\LERNServiceProvider"

Before you run the migration you may want to take a look atconfig/lern.php and change thetable property to a table name that you would like to use. After that run the migration

php artisan migrate

Usage

To use LERN modify the report method in theapp/Exceptions/Handler.php file

publicfunctionreport(Throwable$e){if ($this->shouldReport($e)) {//Check to see if LERN is installed otherwise you will not get an exception.if (app()->bound("lern")) {app()->make("lern")->handle($e);//Record and Notify the Exception/*            OR...            app()->make("lern")->record($e); //Record the Exception to the database            app()->make("lern")->notify($e); //Notify the Exception            */        }    }returnparent::report($e);}

Dont forget to add this to the top of the file

//If you updated your aliases array in "config/app.php"useLERN;useThrowable;//or if you didnt...useTylercd100\LERN\Facades\LERN;useThrowable;

Recording

You can callLERN::record($exception); to record an Exception to the database.To query any Exception that has been recorded you can useExceptionModel which is an Eloquent Model

useTylercd100\LERN\Models\ExceptionModel;$mostRecentException = ExceptionModel::orderBy('created_at','DESC')->first();

To change what is recorded in to the database take a look atconfig/lern.php

'record'=>[/**     * The Model to use     */'model' => \Tylercd100\LERN\Models\ExceptionModel::class,/**     * Database connection to use. Null is the default connection.     */'connection'=>null,/**     * Database table to use     */'table'=>'vendor_tylercd100_lern_exceptions',/**     * Information to store     */'collect'=>['method'=>false,//When true it will collect GET, POST, DELETE, PUT, etc...'data'=>false,//When true it will collect Input data'status_code'=>true,'user_id'=>false,'url'=>false,'ip'=>false,],],

Note: If you changelern.recorder.model thenlern.recorder.table andlern.recorder.connection will be ignored unless you extend\Tylercd100\LERN\Models\ExceptionModel::class

Notifications

LERN uses the Monolog library to send notifications. If you need more than the supported notification channels, then you can add your own custom Monolog handlers. To start using any of the supported handlers just edit the provided config fileconfig/lern.php.

Changing the log level programmatically

Some notification services support different log levels. If changing the config valuelern.notify.log_level is not enough then try it this way:

// Change the log level.// Default is: critical// Options are: debug, info, notice, warning, error, critical, alert, emergencyLERN::setLogLevel("emergency");

Changing the subject line

Some notification services support a subject line, this is how you change it.

//Change the subjectLERN::setSubject("An Exception was thrown!");

Changing the body of the notification

LERN publishes a default blade template file that you can find atresources/views/exceptions/default.blade.php.The blade template file is compiled with these values:$exception$url$method$data$user.To specify a different blade template file, just edit the config file

'notify'=>['view'=>'exceptions.default',],
(deprecated) Using theLERN::setMessage() function

Make sure that you set the view config value to null or theLERN::setMessage() will not work

'notify'=>['view'=>null,],

Custom Monolog Handlers

To use a custom Monolog Handler call thepushHandler method

useMonolog\Handler\SlackHandler;$handler =newSlackHandler($token,$channel);LERN::pushHandler($handler);LERN::notify($exception);

Further Reading and How-Tos

Roadmap

  • Support more Monolog Handlers
  • Exception report page or command to easily identify your application's issues.

About

LERN is a Laravel 5 package that will record exceptions into a database and will notify you via Email, Pushover or Slack.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors12


[8]ページ先頭

©2009-2025 Movatter.jp