1. Go to this page and download the library: Download san4io/request-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/ */
san4io / request-logger example snippets
// in `app/Http/Kernel.php`
protected $middleware = [
...
\San4io\RequestLogger\Middleware\RequestLoggerMiddleware::class
];
// in a routes file
Route::group(['middleware' => \San4io\RequestLogger\Middleware\RequestLoggerMiddleware::class], function () {
//
});
// in a routes file
Route::get('/', function () {
//
})->middleware(\San4io\RequestLogger\Middleware\RequestLoggerMiddleware::class);
// YourServiceProvider.php
public function register()
{
$this->app->bind('app.request.logger', function () {
$logger = new Logger('request-logger');
$handler = new RotatingFileHandler(
storage_path(config('request-logger.storage_path'))
);
// Changing Handler
$handler->setFormatter(new MongoDBFormatter(
env('APP_NAME'),
null,
null,
null
));
$logger->pushHandler($handler);
return $logger;
});
}
//YourServiceProvider.php
public function register()
{
$this->app->bind('my_mega_super_dupper_logger', function () {
...
return $logger;
});
$this->app->bind(RequestLogger::class, function (Application $app) {
return new RequestLogger(
// Injecting your logger
$app->make('my_mega_super_dupper_logger'),
$app->make(LogContextFormatter::class)
);
});
}
// YourServiceProvider.php
public function register()
{
// Totally override LogContextFormatter, in this case it will return only your data.
$this->app->bind(LogContextFormatter::class, function (Application $app) {
$contextFormatter = new LogContextFormatter();
$contextFormatter->addContextFormatter($app->make(YourContextFormatter::class));
return $contextFormatter;
});
// Adding additional contexts to default ones.
$this->app->bind(LogContextFormatter::class, function (Application $app) {
$contextFormatter = $app->make(LogContextFormatter::class);
$contextFormatter->addContextFormatter($app->make(YourContextFormatter::class));
return $contextFormatter;
});
}