How LogProfile and LogWriter work together
mainThe package uses two main abstractions to handle logging:
LogProfile: Determines if a request should be logged. You must implement theshouldLogRequest(Request $request): boolmethod. The default implementation (LogNonGetRequests) only logsPOST,PUT,PATCH,DELETE, andQUERYrequests.LogWriter: Determines how the request is written. You must implement thelogRequest(Request $request): voidmethod. The default implementation (DefaultLogWriter) writes the method, URI, and body (excluding fields in theexceptconfig) to the configured Laravel log channel.
You can swap these out in config/http-logger.php to implement custom logic.
// Example LogProfile implementation
public function shouldLogRequest(Request $request): bool
{
return in_array(strtolower($request->method()), ['post', 'put', 'patch', 'delete', 'query']);
}
// Example LogWriter implementation
public function logRequest(Request $request): void
{
$method = strtoupper($request->getMethod());
$uri = $request->getPathInfo();
$bodyAsJson = json_encode($request->except(config('http-logger.except')));
$message = "{$method} {$uri} - {$bodyAsJson}";
Log::channel(config('http-logger.log_channel'))->info($message);
}