hmdev1/lern
Composer 安装命令:
composer require hmdev1/lern
包简介
LERN (Laravel Exception Recorder and Notifier) is a Laravel 5 package that will record exceptions into a database and will notify you via Email, Pushover or Slack.
README 文档
README
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 via Monolog
- Pushover
- Slack
- Fleephook
- Flowdock
- Plivo an SMS messaging service.
- Twilio an SMS messaging service.
- Sentry via Sentry SDK for PHP
- Mailgun
Version Compatibility
| Laravel | LERN |
|---|---|
| 5.1.x | 3.x |
| 5.2.x | 3.x |
| 5.3.x | 3.x |
| 5.4.x | 3.x |
| 5.5.x | 4.x |
| 5.6.x | 4.x |
| 6.x | 5.x and 6.x |
| 7.x | 6.x |
| 8.x | 6.x |
Migrating from 3.x to 4.x
Make sure that the config file now includes the new lern.notify.class and lern.record.class settings. Check the config file to see how they are used.
Migrating from 2.x to 3.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 new config 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 github php artisan vendor:publish --provider="Tylercd100\LERN\LERNServiceProvider" php artisan migrate
Installation
Version 4.x uses Package Discovery. If you are using 3.x you will need to follow these instructions.
Install via composer - 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 at config/lern.php and change the table 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 the app/Exceptions/Handler.php file
public function report(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 */ } } return parent::report($e); }
Dont forget to add this to the top of the file
//If you updated your aliases array in "config/app.php" use LERN; use Throwable; //or if you didnt... use Tylercd100\LERN\Facades\LERN; use Throwable;
Recording
You can call LERN::record($exception); to record an Exception to the database.
To query any Exception that has been recorded you can use ExceptionModel which is an Eloquent Model
use Tylercd100\LERN\Models\ExceptionModel; $mostRecentException = ExceptionModel::orderBy('created_at','DESC')->first();
To change what is recorded in to the database take a look at config/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 change lern.recorder.model then lern.recorder.table and lern.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 file config/lern.php.
Changing the log level programmatically
Some notification services support different log levels. If changing the config value lern.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, emergency LERN::setLogLevel("emergency");
Changing the subject line
Some notification services support a subject line, this is how you change it.
//Change the subject LERN::setSubject("An Exception was thrown!");
Changing the body of the notification
LERN publishes a default blade template file that you can find at resources/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 the LERN::setMessage() function
Make sure that you set the view config value to null or the LERN::setMessage() will not work
'notify'=>[ 'view'=>null, ],
Custom Monolog Handlers
To use a custom Monolog Handler call the pushHandler method
use Monolog\Handler\SlackHandler; $handler = new SlackHandler($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.
hmdev1/lern 适用场景与选型建议
hmdev1/lern 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 05 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「exceptions」 「monolog」 「laravel」 「pushover」 「slack」 「tylercd100」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 hmdev1/lern 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 hmdev1/lern 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 hmdev1/lern 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
php7ify is a project that brings new php7 classes and exceptions to php 5.x.
A GeoIP decorator/processor for monolog
The CodenamePHP Platform core that contains basic interfaces, exceptions etc..
A Zend Framework module that sets up Monolog for logging in applications.
Laravel 5.6 Monolog custom telegram channel
A Monolog processor to add X-Request-Id or UNIQUE_ID env to monolog stack if present, provide a default one otherwise. Optionally, add a forwarded request-id list.
统计信息
- 总下载量: 11
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 39
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-05-08