PHP code example of weijiajia / saloonphp-logs-plugin
1. Go to this page and download the library: Download weijiajia/saloonphp-logs-plugin 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/ */
weijiajia / saloonphp-logs-plugin example snippets
use Weijiajia\SaloonphpLogsPlugin\Traits\HasLogger;
class ExampleConnector extends Connector
{
use HasLogger;
// set default log
public function getLogger(): ?LoggerInterface
{
return new Logger('saloonphp-logs-plugin');
}
// custom format request log
protected function formatRequestLog(PendingRequest $pendingRequest): ?PendingRequest
{
$requestClass = $pendingRequest->getRequest()::class;
$this->getLogger()?->info("{$requestClass} Request:", [
'connector' => $pendingRequest->getConnector()::class,
'request' => $requestClass,
'method' => $pendingRequest->getMethod(),
'uri' => (string)$pendingRequest->getUri(),
'headers' => $pendingRequest->headers(),
'config' => $pendingRequest->config()->all(),
'body' => (string)$pendingRequest->body(),
]);
return $pendingRequest;
}
// custom format response log
protected function formatResponseLog(Response $response): ?Response
{
$requestClass = $response->getRequest()::class;
$this->getLogger()?->info("{$requestClass} Response:", [
'status' => $response->status(),
'headers' => $response->headers(),
'body' => $response->body(),
]);
return $response;
}
}
$connector = new ExampleConnector();
$connector->withLogger($logger);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.