Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pkg6/think-http-logger
A Thinkphp package to log HTTP requests
https://github.com/pkg6/think-http-logger
log php thinkphp6
Last synced: 7 days ago
JSON representation
A Thinkphp package to log HTTP requests
- Host: GitHub
- URL: https://github.com/pkg6/think-http-logger
- Owner: pkg6
- License: mit
- Created: 2022-05-03T07:54:59.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-07-05T03:37:52.000Z (5 months ago)
- Last Synced: 2024-08-14T12:04:55.964Z (3 months ago)
- Topics: log, php, thinkphp6
- Language: PHP
- Homepage: https://packagist.org/packages/tp5er/think-http-logger
- Size: 28.3 KB
- Stars: 1
- Watchers: 0
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
这个包添加了一个中间件,可以将传入的请求记录到默认日志中。 如果在用户请求期间出现任何问题,您仍然可以访问该用户发送的原始请求数据。
配置文件`config/http-logger.php`内容:
~~~
\tp5er\think\HttpLogger\LogProfile\LogNonGetRequests::class,/*
* The log writer used to write the request to a log.
* It should implement `LogWriter`.
*/
'log_writer' => \tp5er\think\HttpLogger\LogWriter\DefaultLogWriter::class,/*
* The log channel used to write the request.
*/
'log_channel' => env('LOG_CHANNEL', 'file')
];
~~~## 控制器中使用
~~~
use tp5er\think\HttpLogger\Middlewares\HttpLogger;
class Index extends BaseController
{
protected $middleware =[
HttpLogger::class
];
public function index()
{
return 'test HttpLogger';
}
}
~~~## 路由中使用
~~~
Route::get('think', function () {
return 'hello,ThinkPHP6!';
})->middleware(\tp5er\think\HttpLogger\Middlewares\HttpLogger::class);
~~~## 全局`app/middleware.php`
~~~
method()), ['post', 'put', 'patch', 'delete']);
}
~~~自定义日志编写器必须实现 \tp5er\think\HttpLogger\LogWriter。 这个接口需要你实现logRequest。
~~~
// Example implementation from ` \tp5er\think\HttpLogger\DefaultLogWriter`public function logRequest(Request $request): void
{
$method = strtoupper($request->method());
$uri = $request->pathinfo();
$bodyAsJson = json_encode($request->all());
$message = "{$method} {$uri} - {$bodyAsJson}";
Log::channel(config('http-logger.log_channel'))->info($message);
}
~~~