for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Firesphere\SolrSearch\Helpers;
use Firesphere\SolrSearch\Models\SolrLog;
use Firesphere\SolrSearch\Services\SolrCoreService;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use SilverStripe\ORM\ValidationException;
class SolrLogger
{
/**
* @var Client
*/
protected $client;
public function __construct()
$config = SolrCoreService::config()->get('config');
$this->client = new Client(
[
'base_uri' => $config['endpoint']['host'] . ':' . $config['endpoint']['host']['port']
]
);
}
* @param string $type
* @param null|string $index
* @throws GuzzleException
* @throws ValidationException
public function saveSolrLog($type = 'Query', $index = null): void
$response = $this->client->request('GET', 'solr/admin/info/logging', [
'query' => [
'since' => 0,
'wt' => 'json'
]);
$arrayResponse = json_decode($response, true);
foreach ($arrayResponse['history']['docs'] as $error) {
$filter = [
'Timestamp' => $error['time'],
'Level' => $error['level']
];
if (!SolrLog::get()->filter($filter)->first()) {
SolrLog::create([
'Message' => $error['message'],
'Index' => $index,
'Type' => $type,
'Level' => $error['level'],
])->write();