功能描述: 日志中间件,可通过route指定中间件来记录http请求的 header ,body,ip,response信息。并且当response错误时可发生邮件到指定邮箱(这需要配置好laravel自带的Mail)。 这些参数都是可配置的。配置文件如下。
记录的log是在storage/log下,命名规则是每天一个request.log文件。
You can install the package via composer:
composer require daisanmu/laravel-http-logger
Optionally you can publish the configfile with:
php artisan vendor:publish --provider="Daisanmu\HttpLogger\HttpLoggerServiceProvider" --tag="config"
This is the contents of the published config file:
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'
]
];
This packages provides a middleware which can be added as a global middleware or as a single route.
// 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.