aymanalhattami/log-request-response
Composer 安装命令:
composer require aymanalhattami/log-request-response
包简介
Log request, response, headers, method, IP address and URL
关键字:
README 文档
README
Log request, response, headers, method, IP address and URL
NOTE: Logs can be invaluable for debugging issues. By reviewing the request and response data, developers can trace what data was sent and received, and identify where things may have gone wrong
- Useful for logging APIs requests and responses
- Enable/disable logging request
- Enable/disable logging response
- Enable/disable logging headers
- You can specify which request data should be logged
- You can specify which response data should be logged
- You can specify which URLs should be logged
Installation
You can install the package via composer:
composer require aymanalhattami/log-request-response
Usage
Log request and response
use Illuminate\Support\Facades\Route; use AymanAlhattami\LogRequestResponse\Http\Middleware\LogRequestResponseMiddleware; use App\Http\Controllers\ExampleController; # Log all routes Route::middleware(LogRequestResponseMiddleware::class)->group(function() { // routes }); # Log single route Route::get('example', ExampleController::class)->middleware(LogRequestResponseMiddleware::class);
Log request
use Illuminate\Support\Facades\Route; use AymanAlhattami\LogRequestResponse\Http\Middleware\LogRequestMiddleware; use App\Http\Controllers\ExampleController; # Log all routes Route::middleware(LogRequestMiddleware::class)->group(function() { // routes }); # Log single route Route::get('example', ExampleController::class)->middleware(LogRequestMiddleware::class);
Log response
use Illuminate\Support\Facades\Route; use AymanAlhattami\LogRequestResponse\Http\Middleware\LogResponseMiddleware; use App\Http\Controllers\ExampleController; # Log all routes Route::middleware(LogResponseMiddleware::class)->group(function() { // routes }); # Log single route Route::get('example', ExampleController::class)->middleware(LogResponseMiddleware::class);
Log headers
use Illuminate\Support\Facades\Route; use AymanAlhattami\LogRequestResponse\Http\Middleware\LogHeadersMiddleware; use App\Http\Controllers\ExampleController; # Log all routes Route::middleware(LogHeadersMiddleware::class)->group(function() { // routes }); # Log single route Route::get('example', ExampleController::class)->middleware(LogHeadersMiddleware::class);
Configuration
return [ /* Defines the logging level for recording request and response logs. Default: 'info'. */ 'log_level' => env('REQUEST_RESPONSE_LOG_LEVEL', 'info'), 'request' => [ /* Determines whether logging of HTTP requests is enabled. */ 'enabled' => env('LOG_REQUEST', true), /* Title or prefix for request logs, making them easily identifiable. */ 'title' => env('LOG_REQUEST_TITLE', 'Request'), /* Specifies whether headers should be included in the request log. */ 'headers' => env('LOG_HEADERS_WITH_REQUEST', true), /* Indicates whether the request URL should be logged. */ 'url' => env('LOG_REQUEST_URL', true), /* Determines whether the HTTP method should be logged. */ 'method' => env('LOG_REQUEST_METHOD', true), /* Specifies whether the IP address of the requester should be logged. */ 'ip' => env('LOG_REQUEST_IP', true), /* Indicates whether information about the authenticated user should be included in the request log. */ 'auth_user' => env('LOG_AUTH_USER_WITH_REQUEST', true), /* Specifies whether a unique identifier for the request should be logged. */ 'request_id' => env('LOG_REQUEST_ID_WITH_REQUEST', true), /** * Specifying which request data should be logged. * if 'only' has data, then 'except' will be ignored. * if 'except' has data, then 'only' will be ignored. * if both 'only' and 'except' are empty, then all data will be logged. * if both 'only' and 'except' are not empty, then only the data specified in 'only' will be logged. * if 'only' is empty, but 'except' is not empty, then all data except the data specified in 'except' will be logged. * if 'only' is not empty, but 'except' is empty, then only the data specified in 'only' will be logged. */ 'data' => [ 'only' => [], 'except' => ['password', 'password_confirmation'], ], /** * Specifying which URLs should be logged. * if 'only' has data, then 'except' will be ignored. * if 'except' has data, then 'only' will be ignored. * if both 'only' and 'except' are empty, then all URLs will be logged. * if both 'only' and 'except' are not empty, then only the URLs specified in 'only' will be logged. * if 'only' is empty, but 'except' is not empty, then all URLs except the URLs specified in 'except' will be logged. * if 'only' is not empty, but 'except' is empty, then only the URLs specified in 'only' will be logged. */ 'urls' => [ 'only' => [], 'except' => [], ] ], 'response' => [ /* Determines whether logging of HTTP responses is enabled. */ 'enabled' => env('LOG_RESPONSE', true), /* Title or prefix for response logs. */ 'title' => env('LOG_RESPONSE_TITLE', 'Response'), /* Indicates whether information about the authenticated user should be included in the response log. */ 'auth_user' => env('LOG_AUTH_USER_WITH_RESPONSE', true), /* Specifies whether the request's unique identifier should be logged with the response. */ 'request_id' => env('LOG_REQUEST_ID_WITH_RESPONSE', true), /** * Specifying which response data should be logged. * if 'only' has data, then 'except' will be ignored. * if 'except' has data, then 'only' will be ignored. * if both 'only' and 'except' are empty, then all data will be logged. * if both 'only' and 'except' are not empty, then only the data specified in 'only' will be logged. * if 'only' is empty, but 'except' is not empty, then all data except the data specified in 'except' will be logged. * if 'only' is not empty, but 'except' is empty, then only the data specified in 'only' will be logged. */ 'data' => [ 'only' => [], 'except' => [], ] ], 'headers' => [ /* Specifies whether header logging is enabled. */ 'enabled' => env('LOG_HEADERS', true), /* Title or prefix for header logs. */ 'title' => env('LOG_HEADERS_TITLE', 'Headers'), /* Indicates whether information about the authenticated user should be included in the headers log. */ 'auth_user' => env('LOG_AUTH_USER_IN_HEADERS', true), ], /* which data of authenticated user to be logged. Default: 'email'. */ 'auth_user_column' => env('LOG_AUTH_USER_COLUMN', 'email'), /* which guard of authenticated user to be logged. Default: 'api'. */ 'auth_user_guard' => env('LOG_AUTH_USER_GUARD', 'api'), ];
Testing
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email ayman.m.alhattami@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
Laravel Package Boilerplate
This package was generated using the Laravel Package Boilerplate.
aymanalhattami/log-request-response 适用场景与选型建议
aymanalhattami/log-request-response 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 38 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 03 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「log request」 「aymanalhattami」 「log request and response」 「log response」 「log headers」 「log method」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 aymanalhattami/log-request-response 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 aymanalhattami/log-request-response 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 aymanalhattami/log-request-response 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Slim scrollbar for sidebar scrollbar, table scrollbar, and any other scrollbar in the application.
Filament Date Scopes Filter
HTTP request logger middleware for Laravel
A set of classes
Stackdriver handler for Monolog (codeinternetapplications/monolog-stackdriver Fork).
Laravel 5.x.x library for integration Monolog Sentry
统计信息
- 总下载量: 38
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-03-19