2017 © Pedro Peláez
 

library laravel-http-logger

A Laravel package to log HTTP requests, headers and sessions

image

chelout/laravel-http-logger

A Laravel package to log HTTP requests, headers and sessions

  • Friday, April 20, 2018
  • by chelout
  • Repository
  • 2 Watchers
  • 25 Stars
  • 28 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 6 Versions
  • 33 % Grown

The README.md

Log HTTP requests, headers and session data

Latest Stable Version Total Downloads License, (*1)

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., (*2)

Installation

You can install the package via composer:, (*3)

composer require chelout/laravel-http-logger

Optionally you can publish the configfile with:, (*4)

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

This is the contents of the published config file:, (*5)


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., (*6)

// 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:, (*7)

// 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:, (*8)

// 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

bash composer test, (*9)

Changelog

Please see CHANGELOG for more information what has changed recently., (*10)

Inspiration

This package was inspired by Log HTTP requests and Laravel Log Enhancer and Laravel 5.6 logging servises., (*11)

Contributing

Please see CONTRIBUTING for details., (*12)

Credits

License

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

The Versions

20/04 2018

dev-master

9999999-dev https://github.com/chelout/laravel-http-logger

A Laravel package to log HTTP requests, headers and sessions

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel logger http request session header

20/04 2018

dev-develop

dev-develop https://github.com/chelout/laravel-http-logger

A Laravel package to log HTTP requests, headers and sessions

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel logger http request session header

20/04 2018

v1.2.1

1.2.1.0 https://github.com/chelout/laravel-http-logger

A Laravel package to log HTTP requests, headers and sessions

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel logger http request session header

19/04 2018

v1.2.0

1.2.0.0 https://github.com/chelout/laravel-http-logger

A Laravel package to log HTTP requests, headers and sessions

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel logger http request session header

19/04 2018

v1.1.0

1.1.0.0 https://github.com/chelout/laravel-http-logger

A Laravel package to log HTTP requests, headers and sessions

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel logger http request session header

04/04 2018

1.0.0

1.0.0.0 https://github.com/chelout/laravel-http-logger

A Laravel package to log HTTP requests, headers and sessions

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel logger http request session header