Skip to content

Commit

Permalink
remove deprecated log config (ruflin#1661)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobion authored and ruflin committed Sep 12, 2019
1 parent 9990f64 commit 68e6db3
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 330 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ All notable changes to this project will be documented in this file based on the
* Elastica\Reindex->run() does not refresh the new Index after completion anymore. Use `$reindex->setParam(Reindex::REFRESH, 'wait_for')` instead.
* `Elastica\Search->search()` and `Elastica\Search->count()` use request method `POST` by default. Same for `Elastica\Index`, `Elastica\Type\AbstractType`, `Elastica\Type`.
* Elastica\Client `$_config` field is now a `ClientConfiguration` instead of an array
* Removed `\Elastica\Client::_log`, `\Elastica\Log` and the `log` configuration option. Use the `Psr\Log\LoggerInterface $logger` client argument to customize logging.

### Bugfixes
* Always set the Guzzle `base_uri` to support connecting to multiple ES hosts. [#1618](https://github.com/ruflin/Elastica/pull/1618)
Expand Down
50 changes: 10 additions & 40 deletions lib/Elastica/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ public function __construct($config = [], callable $callback = null, LoggerInter

$this->_config = $configuration;
$this->_callback = $callback;

if (!$logger && $configuration->get('log')) {
$logger = new Log($configuration->get('log'));
}
$this->_logger = $logger ?: new NullLogger();

$this->_initConnections();
Expand Down Expand Up @@ -635,7 +631,11 @@ public function request($path, $method = Request::GET, $data = [], array $query
$response = $this->_lastResponse = $request->send();
} catch (ConnectionException $e) {
$this->_connectionPool->onFail($connection, $e, $this);
$this->_log($e);
$this->_logger->error('Elastica Request Failure', [
'exception' => $e,
'request' => $e->getRequest()->toArray(),
'retry' => $this->hasConnection(),
]);

// In case there is no valid connection left, throw exception which caused the disabling of the connection.
if (!$this->hasConnection()) {
Expand All @@ -645,7 +645,11 @@ public function request($path, $method = Request::GET, $data = [], array $query
return $this->request($path, $method, $data, $query);
}

$this->_log($request);
$this->_logger->debug('Elastica Request', [
'request' => $request,
'response' => $this->_lastResponse ? $this->_lastResponse->getData() : null,
'responseStatus' => $this->_lastResponse ? $this->_lastResponse->getStatus() : null,
]);

return $response;
}
Expand All @@ -667,40 +671,6 @@ public function requestEndpoint(AbstractEndpoint $endpoint)
);
}

/**
* logging.
*
* @deprecated Overwriting Client->_log is deprecated. Handle logging functionality by using a custom LoggerInterface.
*
* @param mixed $context
*/
protected function _log($context)
{
if ($context instanceof ConnectionException) {
$this->_logger->error('Elastica Request Failure', [
'exception' => $context,
'request' => $context->getRequest()->toArray(),
'retry' => $this->hasConnection(),
]);

return;
}

if ($context instanceof Request) {
$this->_logger->debug('Elastica Request', [
'request' => $context->toArray(),
'response' => $this->_lastResponse ? $this->_lastResponse->getData() : null,
'responseStatus' => $this->_lastResponse ? $this->_lastResponse->getStatus() : null,
]);

return;
}

$this->_logger->debug('Elastica Request', [
'message' => $context,
]);
}

/**
* Force merges all search indices.
*
Expand Down
2 changes: 0 additions & 2 deletions lib/Elastica/ClientConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class ClientConfiguration
/**
* Config with defaults.
*
* log: Set to true, to enable logging, set a string to log to a specific file
* retryOnConflict: Use in \Elastica\Client::updateDocument
* bigintConversion: Set to true to enable the JSON bigint to string conversion option (see issue #717)
*
Expand All @@ -31,7 +30,6 @@ class ClientConfiguration
'timeout' => null,
'connections' => [], // host, port, path, timeout, transport, compression, persistent, timeout, username, password, config -> (curl, headers, url)
'roundRobin' => false,
'log' => false,
'retryOnConflict' => 0,
'bigintConversion' => false,
'username' => null,
Expand Down
82 changes: 0 additions & 82 deletions lib/Elastica/Log.php

This file was deleted.

9 changes: 2 additions & 7 deletions test/Elastica/ClientConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function testFromSimpleDsn()

$expected = [
'host' => '192.168.1.1',
'port' => '9201',
'port' => 9201,
'path' => null,
'url' => null,
'proxy' => null,
Expand All @@ -33,7 +33,6 @@ public function testFromSimpleDsn()
'timeout' => null,
'connections' => [],
'roundRobin' => false,
'log' => false,
'retryOnConflict' => 0,
'bigintConversion' => false,
'username' => null,
Expand All @@ -45,7 +44,7 @@ public function testFromSimpleDsn()

public function testFromDsnWithParameters()
{
$configuration = ClientConfiguration::fromDsn('https://user:[email protected]:9201/my-path?proxy=https://proxy.com&persistent=false&timeout=45&roundRobin=true&log=true&retryOnConflict=2&bigintConversion=true&extra=abc');
$configuration = ClientConfiguration::fromDsn('https://user:[email protected]:9201/my-path?proxy=https://proxy.com&persistent=false&timeout=45&roundRobin=true&retryOnConflict=2&bigintConversion=true&extra=abc');
$expected = [
'host' => 'foo.com',
'port' => '9201',
Expand All @@ -57,7 +56,6 @@ public function testFromDsnWithParameters()
'timeout' => 45,
'connections' => [],
'roundRobin' => true,
'log' => true,
'retryOnConflict' => 2,
'bigintConversion' => true,
'username' => 'user',
Expand All @@ -83,7 +81,6 @@ public function testFromEmptyArray()
'timeout' => null,
'connections' => [], // host, port, path, timeout, transport, compression, persistent, timeout, username, password, config -> (curl, headers, url)
'roundRobin' => false,
'log' => false,
'retryOnConflict' => 0,
'bigintConversion' => false,
'username' => null,
Expand Down Expand Up @@ -111,7 +108,6 @@ public function testFromArray()
'timeout' => null,
'connections' => [], // host, port, path, timeout, transport, compression, persistent, timeout, username, password, config -> (curl, headers, url)
'roundRobin' => false,
'log' => false,
'retryOnConflict' => 0,
'bigintConversion' => false,
'username' => 'Jdoe',
Expand Down Expand Up @@ -145,7 +141,6 @@ public function testGet()
'timeout' => null,
'connections' => [],
'roundRobin' => false,
'log' => false,
'retryOnConflict' => 0,
'bigintConversion' => false,
'username' => null,
Expand Down
3 changes: 1 addition & 2 deletions test/Elastica/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function testConstructWithDsn()

$expected = [
'host' => 'foo.com',
'port' => '9200',
'port' => 9200,
'path' => null,
'url' => null,
'proxy' => null,
Expand All @@ -50,7 +50,6 @@ public function testConstructWithDsn()
'timeout' => null,
'connections' => [],
'roundRobin' => false,
'log' => false,
'retryOnConflict' => 2,
'bigintConversion' => false,
'username' => 'user',
Expand Down
Loading

0 comments on commit 68e6db3

Please sign in to comment.