定制 aymanalhattami/log-request-response 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

aymanalhattami/log-request-response

Composer 安装命令:

composer require aymanalhattami/log-request-response

包简介

Log request, response, headers, method, IP address and URL

README 文档

README

Latest Version on Packagist Total Downloads

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 我们能提供哪些服务?
定制开发 / 二次开发

基于 aymanalhattami/log-request-response 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 38
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 19
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-03-19