chelout/laravel-http-logger 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

chelout/laravel-http-logger

Composer 安装命令:

composer require chelout/laravel-http-logger

包简介

A Laravel package to log HTTP requests, headers and sessions

README 文档

README

Latest Stable Version Total Downloads License

This package provides a middleware to log incoming http requests data (body data, files, headers and session data). It utilizes Laravel 5.6 logging servises functionality. This package might be useful to log user requests to public apis.

Installation

You can install the package via composer:

composer require chelout/laravel-http-logger

Optionally you can publish the configfile with:

php artisan vendor:publish --provider="Chelout\HttpLogger\HttpLoggerServiceProvider" --tag="config" 

This is the contents of the published config file:

return [
    /*
     * Log file path
     */
    'path' => storage_path('logs/http.log'),
    /*
     * The maximal amount of files to keep (0 means unlimited)
     */
    'max_files' => 5,

    /*
     * Log methods
     * [] - log all methods
     * ['get','post'] - log only 'get' and 'post' methods
     */
    'methods' => [],

    /*
     * Log message format.
     * For for details see https://github.com/Seldaek/monolog/blob/master/doc/01-usage.md#customizing-the-log-format
     * and https://github.com/Seldaek/monolog/blob/master/src/Monolog/Formatter/LineFormatter.php
     */
    'format' => "[%datetime%] %extra.method% %extra.url% from %extra.ips% %context%\n",

    /*
     * Log message datetime format.
     * For for details see https://github.com/Seldaek/monolog/blob/master/doc/01-usage.md#customizing-the-log-format
     * and https://github.com/Seldaek/monolog/blob/master/src/Monolog/Formatter/LineFormatter.php
     */
    'date_format' => null, // "Y-m-d\TH:i:sP"

    /*
     * Log current memory usage
     * @see https://github.com/Seldaek/monolog/blob/master/src/Monolog/Processor/MemoryUsageProcessor.php
     */
    'memory_usage' => true,

    /*
     * Log peak memory usage
     * @see https://github.com/Seldaek/monolog/blob/master/src/Monolog/Processor/MemoryPeakUsageProcessor.php
     */
    'memory_peak_usage' => true,

    /*
     * Log current git branch and commit
     * @see https://github.com/Seldaek/monolog/blob/master/src/Monolog/Processor/GitProcessor.php
     */
    'git' => true,

    /*
     * false - don't log body fields
     * ['only'] - log fields only
     * ['except'] - don't log fields
     *
     * If ['only'] is set, ['except'] parametr will be omitted
     */
    // 'data' => false,
    'data' => [
        'only' => [],
        'except' => [],
    ],

    /*
     * false - don't log uploaded files
     * ['only'] - log files only
     * ['except'] - don't log files
     *
     * If ['only'] is set, ['except'] parametr will be omitted
     */
    // 'files' => false,
    'files' => [
        'only' => [],
        'except' => [],
    ],

    /*
     * false - don't log headers
     * ['only'] - log headers only
     * ['except'] - don't log headers
     *
     * If ['only'] is set, ['except'] parametr will be omitted
     */
    // 'headers' => false,
    'headers' => [
        'only' => ['user-agent'],
        'except' => [],
    ],

    /*
     * false - don't log session
     * ['only'] - log session only
     * ['except'] - don't log session
     *
     * If ['only'] is set, ['except'] parametr will be omitted
     */
    'session' => false,
    // 'session' => [
    //     'only' => [],
    //     'except' => [],
    // ],
];

Usage

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 = [
    // ...
    
    \Chelout\HttpLogger\Middlewares\HttpLogger::class
];
// in a routes file

Route::post('/submit-form', function () {
    //
})->middleware(\Chelout\HttpLogger\Middlewares\HttpLogger::class);

In order to log http requests you should add log custom log channel:

// in config/logging.php

return [
    // ...

    'channels' => [
        // ...

        'http-logger' => [
            'driver' => 'custom',
            'via' => \Chelout\HttpLogger\Loggers\HttpLogger::class,
        ],
    ],
];

You can also enhance existing log channel by customizing Monolog configuration:

// in config/logging.php

return [
    // ...

    'channels' => [
        // ...

        'single' => [
            'driver' => 'single',
            'tap' => [Chelout\HttpLogger\Loggers\MonologCustomizer::class],
            'path' => storage_path('logs/laravel.log'),
            'level' => 'debug',
        ],
    ],
];

Todo

  • tests
  • log git data?
  • log memory usage?

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Inspiration

This package was inspired by Log HTTP requests and Laravel Log Enhancer and Laravel 5.6 logging servises.

Contributing

Please see CONTRIBUTING for details.

Credits

License

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

统计信息

  • 总下载量: 2.04k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 27
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 26
  • Watchers: 2
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-04-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固