1. Go to this page and download the library: Download partner-api/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/ */
partner-api / logger example snippets
use PartnerApi\Logger\Laravel\Facades\PartnerLogger;
$apiKey = (string) $request->header('x-api-key'); // sent by the partner app
PartnerLogger::info($apiKey, 'Order created', ['orderId' => $order->id]);
use PartnerApi\Logger\Logger;
$logger = new Logger(tenantToken: getenv('PARTNER_API_TENANT_TOKEN'));
$logger->info($apiKey, 'Order created', ['orderId' => 42]);
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use PartnerApi\Logger\Logger;
class ScopePartnerLogs
{
public function __construct(private Logger $logger)
{
}
public function handle(Request $request, Closure $next)
{
return $this->logger->runWithContext(
['requestId' => $request->header('x-request-id')],
fn () => $next($request),
);
}
}
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
// Once, where you build the client. Every request through it is recorded
// against the request that makes it.
$stack = HandlerStack::create();
$stack->push($logger->upstreamMiddleware('stripe'));
$stripe = new Client(['handler' => $stack]);
// In a handler:
$correlationId = $logger->logRequest($apiKey, ['method' => 'POST', 'path' => '/orders']);
$stripe->post('https://api.stripe.com/v1/charges', ['form_params' => ['amount' => 1000]]);
// Anything that is not Guzzle: record it yourself.
$logger->upstream([
'name' => 'pricing',
'method' => 'GET',
'url' => 'https://pricing.internal/quote',
'status' => 200,
'durationMs' => 41,
]);
$logger->logResponse($apiKey, ['statusCode' => 201, 'duration' => 250, 'correlationId' => $correlationId]);