定制 dniccum/laravel-request-logs 二次开发

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

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

dniccum/laravel-request-logs

Composer 安装命令:

composer require dniccum/laravel-request-logs

包简介

Log and debug HTTP requests within your Laravel application.

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Provide insight to your application's requests with this Laravel-specific package. Simply add a light-weight middleware to your application and capture all the requests' body, headers, and responses. A console command is also provided that can be used to purge the logs to prevent any dated, unwanted bloat.

Installation

You can install the package via composer:

composer require dniccum/laravel-request-logs

You can publish and run the migrations with:

php artisan vendor:publish --tag="laravel-request-logs-migrations"
php artisan migrate --force

You can publish the config file with:

php artisan vendor:publish --tag="laravel-request-logs-config"

This is the contents of the published config file:

return [

    /*
    |--------------------------------------------------------------------------
    | Table Name
    |--------------------------------------------------------------------------
    |
    | The name of the table that will store the log entries.
    |
    */

    'table_name' => 'request_logs',

    /*
    |--------------------------------------------------------------------------
    | History
    |--------------------------------------------------------------------------
    |
    | The number of days of logs that you would like to keep in the database
    | at any time.
    |
    */

    'history' => env('LOGGING_HISTORY', 21),

    /*
    |--------------------------------------------------------------------------
    | Remove Bearer Token
    |--------------------------------------------------------------------------
    |
    | Enable if you would like to remove the bearer authentication token from
    | the request header.
    |
    */

    'remove_bearer' => env('LOGGING_REMOVE_BEARER', true),

];

Usage

Middleware

Adding to Middleware Groups

If you would like to use this package's middleware across a large group of requests, like all of your api routes, you can apply it to your applications api middleware group within your app/Http/Kernel.php like so:

protected $middlewareGroups = [
        'web' => [
            ...
        ],

        'api' => [
            ...
            \Dniccum\LaravelRequestLogs\Http\Middleware\RequestLogging::class,
        ],
    ];

Adding to specific routes

On the other hand, if you are wanting to add some logging clarity to specific routes, you can define it as a route middleware within your app/Http/Kernel.php:

/**
     * The application's route middleware.
     *
     * These middleware may be assigned to groups or used individually.
     *
     * @var array
     */
    protected $routeMiddleware = [
        ...
        'route-logging' => \Dniccum\LaravelRequestLogs\Http\Middleware\RequestLogging::class
    ];

and then assign it to a specific route within your routes file:

Route::post('/create-project', [ \App\Http\Controllers\SampleController::class, 'create' ])
    ->middleware([ 'route-logging' ]);

IMPORTANT: Response Body Length Limit

Assuming that your database migration and model are unchanged, there is currently logic in place that will prevent the response_body column from being overloaded. What does this mean? In the event that the response body of the request that you are logging is very large (ie returning 500+ results from an API), the number of bytes/characters might be too large for the database to store without failing. If the response body is longer than 65,000 characters, the response body will NOT be saved.

Log Cleanup (optional)

Note – this is not required but HIGHLY recommended as this could lead to large amounts of data within your database in short periods of time.

To automate the removal of older logs you can either use the provided artisan command php artisan request-logs:clean manually with your app's environment, or you can leverage your app's scheduler process within your app/Console/Kernel.php file to automate it like so:

$schedule->job(\Dniccum\LaravelRequestLogs\Commands\CleanReqeustLogsCommand::class)
    ->daily();

Stored History

By default, this package will retain 21 days of logs. This can be changed via environment variable (LOGGING_HISTORY) or simply modifying it within the request-logs.php configuration file.

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.

dniccum/laravel-request-logs 适用场景与选型建议

dniccum/laravel-request-logs 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6 次下载、GitHub Stars 达 14, 最近一次更新时间为 2022 年 10 月 17 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「logs」 「dniccum」 「request-logs」 「laravel-request-logs」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 dniccum/laravel-request-logs 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 dniccum/laravel-request-logs 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 14
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-10-17