第三目 / laravel-http-logger
Laravel 5 包用于记录 HTTP 请求
1.1.4
2018-12-11 05:39 UTC
Requires
- php: ^7.1
- illuminate/support: ~5.6.0|~5.7.0
Requires (Dev)
- orchestra/testbench: ~3.6.0|~3.7.0
- phpunit/phpunit: ^7.0
README
功能描述:日志中间件,可以通过 route 指定中间件来记录 HTTP 请求的 header、body、ip、response 信息。并且当 response 出错时可以发送邮件到指定邮箱(这需要配置好 Laravel 自带的 Mail)。这些参数都是可配置的。配置文件如下。
记录的日志位于 storage/log 目录下,命名规则是每天一个 request.log 文件。
安装
您可以通过 composer 安装此包
composer require daisanmu/laravel-http-logger
可选地,您可以使用以下命令发布配置文件:
php artisan vendor:publish --provider="Daisanmu\HttpLogger\HttpLoggerServiceProvider" --tag="config"
这是发布后的配置文件内容
return [ /* * The log profile which determines whether a request should be logged. * It should implement `LogProfile`. */ 'log_profile' => \Daisanmu\HttpLogger\LogNonGetRequests::class, /* * The log writer used to write the request to a log. * It should implement `LogWriter`. */ 'log_writer' => \Daisanmu\HttpLogger\DefaultLogWriter::class, /* * Filter out body fields which will never be logged. */ 'except' => [ 'password', 'password_confirmation', ], /* * Filter out header fields which will never be logged. */ 'except_header' => [ 'postman-token', 'accept', 'accept-language', 'accept-encoding', 'cache-control', 'content-type', 'content-length', 'connection', 'host', 'user-agent', 'origin' ], /** *指定错误发送邮件 */ 'send_mail_status' => [ '500' ], /** *指定到指定邮箱,需要配置laravel的Mail */ 'send_to' => [ '10503331@qq.com' ] ];
使用方法
此包提供了一个中间件,可以将其添加为全局中间件或单个路由中间件。
// in `app/Http/Kernel.php` protected $middleware = [ // ... \Spatie\HttpLogger\Middlewares\HttpLogger::class ];
// in a routes file Route::post('/submit-form', function () { // })->middleware(\Spatie\HttpLogger\Middlewares\HttpLogger::class);
在 spatie/laravel-http-logger 的基础上增加了记录 header IP 和 response 信息,当 response 为指定错误码时可以发送邮件
fork 自 https://github.com/spatie/laravel-http-logger
## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.