1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-07-31 18:30:15 +02:00

Rename ElasticSearch to Elasticsearch

This commit is contained in:
Avtandil Kikabidze
2018-06-27 11:48:39 +04:00
parent 34e3a48326
commit 4c7795d310
7 changed files with 67 additions and 67 deletions

View File

@@ -1,7 +1,7 @@
### 2.0.0
- Added support for official ElasticSearch client. To avoid name collision,
old `ElasticSearchHandler` renamed to `ElasticaHandler`
- Added support for official Elasticsearch client. To avoid name collision,
old `ElasticsearchHandler` renamed to `ElasticaHandler`
- The timezone is now set per Logger instance and not statically, either
via ->setTimezone or passed in the constructor. Calls to Logger::setTimezone

View File

@@ -37,7 +37,7 @@
"sentry/sentry": "Allow sending log messages to a Sentry server",
"doctrine/couchdb": "Allow sending log messages to a CouchDB server",
"ruflin/elastica": "Allow sending log messages to an Elastic Search server",
"elasticsearch/elasticsearch": "Allow sending log messages to an Elastic Search server via official client",
"elasticsearch/elasticsearch": "Allow sending log messages to an Elasticsearch server via official client",
"php-amqplib/php-amqplib": "Allow sending log messages to an AMQP server using php-amqplib",
"ext-amqp": "Allow sending log messages to an AMQP server (1.0+ required)",
"ext-mongodb": "Allow sending log messages to a MongoDB server (via driver)",

View File

@@ -81,7 +81,7 @@
[Mongo](http://pecl.php.net/package/mongo) extension connection.
- [_CouchDBHandler_](../src/Monolog/Handler/CouchDBHandler.php): Logs records to a CouchDB server.
- [_DoctrineCouchDBHandler_](../src/Monolog/Handler/DoctrineCouchDBHandler.php): Logs records to a CouchDB server via the Doctrine CouchDB ODM.
- [_ElasticSearchHandler_](../src/Monolog/Handler/ElasticSearchHandler.php): Logs records to an Elastic Search server.
- [_ElasticsearchHandler_](../src/Monolog/Handler/ElasticsearchHandler.php): Logs records to an Elasticsearch server.
- [_DynamoDbHandler_](../src/Monolog/Handler/DynamoDbHandler.php): Logs records to a DynamoDB table with the [AWS SDK](https://github.com/aws/aws-sdk-php).
### Wrappers / Special Handlers

View File

@@ -14,29 +14,29 @@ namespace Monolog\Formatter;
use DateTime;
/**
* Format a log message into an ElasticSearch record
* Format a log message into an Elasticsearch record
*
* @author Avtandil Kikabidze <akalongman@gmail.com>
*/
class ElasticSearchFormatter extends NormalizerFormatter
class ElasticsearchFormatter extends NormalizerFormatter
{
/**
* @var string ElasticSearch index name
* @var string Elasticsearch index name
*/
protected $index;
/**
* @var string ElasticSearch record type
* @var string Elasticsearch record type
*/
protected $type;
/**
* @param string $index ElasticSearch index name
* @param string $type ElasticSearch record type
* @param string $index Elasticsearch index name
* @param string $type Elasticsearch record type
*/
public function __construct($index, $type)
{
// ElasticSearch requires an ISO 8601 format date with optional millisecond precision.
// Elasticsearch requires an ISO 8601 format date with optional millisecond precision.
parent::__construct(DateTime::ISO8601);
$this->index = $index;
@@ -74,7 +74,7 @@ class ElasticSearchFormatter extends NormalizerFormatter
}
/**
* Convert a log message into an ElasticSearch record
* Convert a log message into an Elasticsearch record
*
* @param array $record Log message
* @return array

View File

@@ -12,36 +12,36 @@
namespace Monolog\Handler;
use Elasticsearch\Client;
use Elasticsearch\Common\Exceptions\RuntimeException as ElasticSearchRuntimeException;
use Elasticsearch\Common\Exceptions\RuntimeException as ElasticsearchRuntimeException;
use InvalidArgumentException;
use Monolog\Formatter\ElasticSearchFormatter;
use Monolog\Formatter\ElasticsearchFormatter;
use Monolog\Formatter\FormatterInterface;
use Monolog\Logger;
use RuntimeException;
use Throwable;
/**
* Elastic Search handler
* Elasticsearch handler
*
* @link https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/index.html
*
* Simple usage example:
*
* $client = \ElasticSearch\ClientBuilder::create()
* $client = \Elasticsearch\ClientBuilder::create()
* ->setHosts($hosts)
* ->build();
*
* $options = array(
* 'index' => 'elastic_index_name',
* 'type' => 'elastic_doc_type',
* 'type' => 'elastic_doc_type',
* );
* $handler = new ElasticSearchHandler($client, $options);
* $handler = new ElasticsearchHandler($client, $options);
* $log = new Logger('application');
* $log->pushHandler($handler);
*
* @author Avtandil Kikabidze <akalongman@gmail.com>
*/
class ElasticSearchHandler extends AbstractProcessingHandler
class ElasticsearchHandler extends AbstractProcessingHandler
{
/**
* @var \Elasticsearch\Client
@@ -54,7 +54,7 @@ class ElasticSearchHandler extends AbstractProcessingHandler
protected $options = [];
/**
* @param \Elasticsearch\Client $client ElasticSearch Client object
* @param \Elasticsearch\Client $client Elasticsearch Client object
* @param array $options Handler configuration
* @param int $level The minimum logging level at which this handler will be triggered
* @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not
@@ -67,7 +67,7 @@ class ElasticSearchHandler extends AbstractProcessingHandler
[
'index' => 'monolog', // Elastic index name
'type' => '_doc', // Elastic document type
'ignore_error' => false, // Suppress ElasticSearch exceptions
'ignore_error' => false, // Suppress Elasticsearch exceptions
],
$options
);
@@ -86,10 +86,10 @@ class ElasticSearchHandler extends AbstractProcessingHandler
*/
public function setFormatter(FormatterInterface $formatter): HandlerInterface
{
if ($formatter instanceof ElasticSearchFormatter) {
if ($formatter instanceof ElasticsearchFormatter) {
return parent::setFormatter($formatter);
}
throw new InvalidArgumentException('ElasticSearchHandler is only compatible with ElasticSearchFormatter');
throw new InvalidArgumentException('ElasticsearchHandler is only compatible with ElasticsearchFormatter');
}
/**
@@ -107,7 +107,7 @@ class ElasticSearchHandler extends AbstractProcessingHandler
*/
protected function getDefaultFormatter(): FormatterInterface
{
return new ElasticSearchFormatter($this->options['index'], $this->options['type']);
return new ElasticsearchFormatter($this->options['index'], $this->options['type']);
}
/**
@@ -120,7 +120,7 @@ class ElasticSearchHandler extends AbstractProcessingHandler
}
/**
* Use ElasticSearch bulk API to send list of documents
* Use Elasticsearch bulk API to send list of documents
*
* @param array $records
* @throws \RuntimeException
@@ -147,11 +147,11 @@ class ElasticSearchHandler extends AbstractProcessingHandler
$responses = $this->client->bulk($params);
if ($responses['errors'] === true) {
throw new ElasticSearchRuntimeException('ElasticSearch returned error for one of the records');
throw new ElasticsearchRuntimeException('Elasticsearch returned error for one of the records');
}
} catch (Throwable $e) {
if (! $this->options['ignore_error']) {
throw new RuntimeException('Error sending messages to ElasticSearch', 0, $e);
throw new RuntimeException('Error sending messages to Elasticsearch', 0, $e);
}
}
}

View File

@@ -13,12 +13,12 @@ namespace Monolog\Formatter;
use Monolog\Logger;
class ElasticSearchFormatterTest extends \PHPUnit\Framework\TestCase
class ElasticsearchFormatterTest extends \PHPUnit\Framework\TestCase
{
/**
* @covers Monolog\Formatter\ElasticSearchFormatter::__construct
* @covers Monolog\Formatter\ElasticSearchFormatter::format
* @covers Monolog\Formatter\ElasticSearchFormatter::getDocument
* @covers Monolog\Formatter\ElasticsearchFormatter::__construct
* @covers Monolog\Formatter\ElasticsearchFormatter::format
* @covers Monolog\Formatter\ElasticsearchFormatter::getDocument
*/
public function testFormat()
{
@@ -43,7 +43,7 @@ class ElasticSearchFormatterTest extends \PHPUnit\Framework\TestCase
];
// Format log message
$formatter = new ElasticSearchFormatter('my_index', 'doc_type');
$formatter = new ElasticsearchFormatter('my_index', 'doc_type');
$doc = $formatter->format($msg);
$this->assertInternalType('array', $doc);
@@ -58,12 +58,12 @@ class ElasticSearchFormatterTest extends \PHPUnit\Framework\TestCase
}
/**
* @covers Monolog\Formatter\ElasticSearchFormatter::getIndex
* @covers Monolog\Formatter\ElasticSearchFormatter::getType
* @covers Monolog\Formatter\ElasticsearchFormatter::getIndex
* @covers Monolog\Formatter\ElasticsearchFormatter::getType
*/
public function testGetters()
{
$formatter = new ElasticSearchFormatter('my_index', 'doc_type');
$formatter = new ElasticsearchFormatter('my_index', 'doc_type');
$this->assertEquals('my_index', $formatter->getIndex());
$this->assertEquals('doc_type', $formatter->getType());
}

View File

@@ -12,13 +12,13 @@
namespace Monolog\Handler;
use Elasticsearch\ClientBuilder;
use Monolog\Formatter\ElasticSearchFormatter;
use Monolog\Formatter\ElasticsearchFormatter;
use Monolog\Formatter\NormalizerFormatter;
use Monolog\Test\TestCase;
use Monolog\Logger;
use Elasticsearch\Client;
class ElasticSearchHandlerTest extends TestCase
class ElasticsearchHandlerTest extends TestCase
{
/**
* @var Client mock
@@ -35,12 +35,12 @@ class ElasticSearchHandlerTest extends TestCase
public function setUp()
{
// ElasticSearch lib required
// Elasticsearch lib required
if (!class_exists('Elasticsearch\Client')) {
$this->markTestSkipped('elasticsearch/elasticsearch not installed');
}
// base mock ElasticSearch Client object
// base mock Elasticsearch Client object
$this->client = $this->getMockBuilder('Elasticsearch\Client')
->setMethods(['bulk'])
->disableOriginalConstructor()
@@ -48,10 +48,10 @@ class ElasticSearchHandlerTest extends TestCase
}
/**
* @covers Monolog\Handler\ElasticSearchHandler::write
* @covers Monolog\Handler\ElasticSearchHandler::handleBatch
* @covers Monolog\Handler\ElasticSearchHandler::bulkSend
* @covers Monolog\Handler\ElasticSearchHandler::getDefaultFormatter
* @covers Monolog\Handler\ElasticsearchHandler::write
* @covers Monolog\Handler\ElasticsearchHandler::handleBatch
* @covers Monolog\Handler\ElasticsearchHandler::bulkSend
* @covers Monolog\Handler\ElasticsearchHandler::getDefaultFormatter
*/
public function testHandle()
{
@@ -67,7 +67,7 @@ class ElasticSearchHandlerTest extends TestCase
];
// format expected result
$formatter = new ElasticSearchFormatter($this->options['index'], $this->options['type']);
$formatter = new ElasticsearchFormatter($this->options['index'], $this->options['type']);
$data = $formatter->format($msg);
unset($data['_index'], $data['_type']);
@@ -89,39 +89,39 @@ class ElasticSearchHandlerTest extends TestCase
->with($expected);
// perform tests
$handler = new ElasticSearchHandler($this->client, $this->options);
$handler = new ElasticsearchHandler($this->client, $this->options);
$handler->handle($msg);
$handler->handleBatch([$msg]);
}
/**
* @covers Monolog\Handler\ElasticSearchHandler::setFormatter
* @covers Monolog\Handler\ElasticsearchHandler::setFormatter
*/
public function testSetFormatter()
{
$handler = new ElasticSearchHandler($this->client);
$formatter = new ElasticSearchFormatter('index_new', 'type_new');
$handler = new ElasticsearchHandler($this->client);
$formatter = new ElasticsearchFormatter('index_new', 'type_new');
$handler->setFormatter($formatter);
$this->assertInstanceOf('Monolog\Formatter\ElasticSearchFormatter', $handler->getFormatter());
$this->assertInstanceOf('Monolog\Formatter\ElasticsearchFormatter', $handler->getFormatter());
$this->assertEquals('index_new', $handler->getFormatter()->getIndex());
$this->assertEquals('type_new', $handler->getFormatter()->getType());
}
/**
* @covers Monolog\Handler\ElasticSearchHandler::setFormatter
* @covers Monolog\Handler\ElasticsearchHandler::setFormatter
* @expectedException InvalidArgumentException
* @expectedExceptionMessage ElasticSearchHandler is only compatible with ElasticSearchFormatter
* @expectedExceptionMessage ElasticsearchHandler is only compatible with ElasticsearchFormatter
*/
public function testSetFormatterInvalid()
{
$handler = new ElasticSearchHandler($this->client);
$handler = new ElasticsearchHandler($this->client);
$formatter = new NormalizerFormatter();
$handler->setFormatter($formatter);
}
/**
* @covers Monolog\Handler\ElasticSearchHandler::__construct
* @covers Monolog\Handler\ElasticSearchHandler::getOptions
* @covers Monolog\Handler\ElasticsearchHandler::__construct
* @covers Monolog\Handler\ElasticsearchHandler::getOptions
*/
public function testOptions()
{
@@ -130,12 +130,12 @@ class ElasticSearchHandlerTest extends TestCase
'type' => $this->options['type'],
'ignore_error' => false,
];
$handler = new ElasticSearchHandler($this->client, $this->options);
$handler = new ElasticsearchHandler($this->client, $this->options);
$this->assertEquals($expected, $handler->getOptions());
}
/**
* @covers Monolog\Handler\ElasticSearchHandler::bulkSend
* @covers Monolog\Handler\ElasticsearchHandler::bulkSend
* @dataProvider providerTestConnectionErrors
*/
public function testConnectionErrors($ignore, $expectedError)
@@ -146,7 +146,7 @@ class ElasticSearchHandlerTest extends TestCase
->build();
$handlerOpts = ['ignore_error' => $ignore];
$handler = new ElasticSearchHandler($client, $handlerOpts);
$handler = new ElasticsearchHandler($client, $handlerOpts);
if ($expectedError) {
$this->expectException($expectedError[0]);
@@ -163,18 +163,18 @@ class ElasticSearchHandlerTest extends TestCase
public function providerTestConnectionErrors()
{
return [
[false, ['RuntimeException', 'Error sending messages to ElasticSearch']],
[false, ['RuntimeException', 'Error sending messages to Elasticsearch']],
[true, false],
];
}
/**
* Integration test using localhost Elastic Search server
* Integration test using localhost Elasticsearch server
*
* @covers Monolog\Handler\ElasticSearchHandler::__construct
* @covers Monolog\Handler\ElasticSearchHandler::handleBatch
* @covers Monolog\Handler\ElasticSearchHandler::bulkSend
* @covers Monolog\Handler\ElasticSearchHandler::getDefaultFormatter
* @covers Monolog\Handler\ElasticsearchHandler::__construct
* @covers Monolog\Handler\ElasticsearchHandler::handleBatch
* @covers Monolog\Handler\ElasticsearchHandler::bulkSend
* @covers Monolog\Handler\ElasticsearchHandler::getDefaultFormatter
*/
public function testHandleIntegration()
{
@@ -200,12 +200,12 @@ class ElasticSearchHandlerTest extends TestCase
$client = ClientBuilder::create()
->setHosts($hosts)
->build();
$handler = new ElasticSearchHandler($client, $this->options);
$handler = new ElasticsearchHandler($client, $this->options);
try {
$handler->handleBatch([$msg]);
} catch (\RuntimeException $e) {
$this->markTestSkipped('Cannot connect to Elastic Search server on localhost');
$this->markTestSkipped('Cannot connect to Elasticsearch server on localhost');
}
// check document id from ES server response
@@ -229,7 +229,7 @@ class ElasticSearchHandlerTest extends TestCase
/**
* Return last created document id from ES response
*
* @param array $info ElasticSearch last request info
* @param array $info Elasticsearch last request info
* @return string|null
*/
protected function getCreatedDocId(array $info)
@@ -244,7 +244,7 @@ class ElasticSearchHandlerTest extends TestCase
/**
* Retrieve document by id from Elasticsearch
*
* @param Client $client ElasticSearch client
* @param Client $client Elasticsearch client
* @param string $index
* @param string $type
* @param string $documentId