return [
/**
* The model used to manage the database table for storing request and response logs.
*/
'logging_model' => \Mtownsend\RequestResponseLogger\Models\RequestResponseLog::class,
/**
* When logging requests and responses, should the logging action be
* passed off to the queue (true) or run synchronously (false)?
*/
'logging_should_queue' => false,
/**
* If stored json should be transformed into an array when retrieved from the database.
* Set to `false` to receive as a regular php object.
*/
'get_json_values_as_array' => true,
/**
* The class responsible for determining if a request should be logged.
*
* Out of the box options are:
* Mtownsend\RequestResponseLogger\Support\Logging\LogAll::class,
* Mtownsend\RequestResponseLogger\Support\Logging\LogClientErrorsOnly::class,
* Mtownsend\RequestResponseLogger\Support\Logging\LogSuccessOnly::class,
*/
'should_log_handler' => \Mtownsend\RequestResponseLogger\Support\Logging\LogAll::class,
];
protected function schedule(Schedule $schedule)
{
...
$schedule->command('request-response-logger:clean')->quarterly();
}
namespace App\Support\Logging;
use Illuminate\Http\Request;
use Mtownsend\RequestResponseLogger\Support\Logging\Contracts\ShouldLogContract;
class LogExternalRequests implements ShouldLogContract
{
public $request;
public $response;
public function __construct(Request $request, $response)
{
$this->request = $request;
$this->response = $response;
}
/**
* Return a truth-y value to log the request and response.
* Return false-y value to skip logging.
*
* @return bool
*/
public function shouldLog(): bool
{
// Custom logic goes here...
}
}
use Mtownsend\RequestResponseLogger\Models\RequestResponseLog;
// Get every logged item with an http response code of 2XX:
RequestResponseLog::successful()->get();
// Get every logged item with an http response code that ISN'T 2XX:
RequestResponseLog::failed()->get();
namespace App\Models;
use Mtownsend\RequestResponseLogger\Models\RequestResponseLog as BaseRequestResponseLog;
class RequestResponseLog extends BaseRequestResponseLog
{
//
}