PHP code example of cndrsdrmn / http-logger

1. Go to this page and download the library: Download cndrsdrmn/http-logger library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cndrsdrmn / http-logger example snippets


return [
	
	/*
	 |-----------------------------------------------------------
	 | HTTP Logger Channel
	 |-----------------------------------------------------------
	 */
	'channel' => env('HTTP_LOGGER_CHANNEL', env('LOG_CHANNEL', 'stack')),
	
	/*
	 |-----------------------------------------------------------
	 | Masking Fields
	 |-----------------------------------------------------------
	 |
	 | Sometimes you need to keep field values secretly.
	 | You can register a field on this "masking" key to keep its value secret.
	 | Masked a request "body", "query" and "headers".
	 */
	'masking' => [
	    'password',
	    'password_confirmation',
	],
	
	/*
	 |-----------------------------------------------------------
	 | Skip Endpoints
	 |-----------------------------------------------------------
	 |
	 | Sometimes, you need to skip recording a log for whitelist endpoints.
	 | Example: '/foo/bar', '/foo/*'
	 */
	'skip_endpoints' => [],
	
	/*
	 |-----------------------------------------------------------
	 | Skip IPs Address
	 |-----------------------------------------------------------
	 |
	 | Sometimes, you need to skip recording a log for whitelist IPs address.
	 | Example: '192.168.0.10', '172.10.0.*', '172.9.*',
	 */
	'skip_ips' => [],
];

// in config/logging.php

'channels' => [
    // ...
    'http-logger' => [
        'driver' => 'daily',
        'path' => storage_path('logs/http-loggers/http-logger.log'),
        'level' => 'debug',
        'days' => 14,
    ],
    // ...
]

// in .env file
HTTP_LOGGER_CHANNEL=http-logger

$app->withFacades();

// in app/Http/Kernel.php
protected $middleware = [
    // ...
    \Cndrsdrmn\HttpLogger\Middleware\HttpLogger::class,
];

// in a routes file
Route::post('foo', function () {
    // action here
})->middleware(\Cndrsdrmn\HttpLogger\Middleware\HttpLogger::class);

// in bootstrap/app.php

// Global Middleware
$app->middleware([
   \Cndrsdrmn\HttpLogger\Middleware\HttpLogger::class,
]);

// OR Assigning Middleware To Routes
$app->routeMiddleware([
    'http-logger' => \Cndrsdrmn\HttpLogger\Middleware\HttpLogger::class,
]);

// in routes file
$router->get('/', ['middleware' => ['http-logger'], function () {
    //
}]);

$app->configure('http-logger');
shell
php artisan vendor:publish --provider="Cndrsdrmn\HttpLogger\HttpLoggerServiceProvider" --tag="config"