'elastic_index_name', * 'type' => 'elastic_doc_type', Types have been removed in Elastica 7 * ); * $handler = new ElasticaHandler($client, $options); * $log = new Logger('application'); * $log->pushHandler($handler); * * @author Jelle Vink */ class ElasticaHandler extends AbstractProcessingHandler { /** @var Client */ protected $client; /** @var mixed[] Handler config options */ protected $options = []; /** * @param Client $client Elastica Client object * @param mixed[] $options Handler configuration */ public function __construct(Client $client, array $options = [], $level = Logger::DEBUG, bool $bubble = true) { parent::__construct($level, $bubble); $this->client = $client; $this->options = array_merge( [ 'index' => 'monolog', // Elastic index name "type" => 'record', // Elastic document type "ignore_error" => false, // Suppress Elastica exceptions ], $options ); } /** * {@inheritDoc} */ protected function write(array $record): void { $this->bulkSend([$record['formatted']]); } /** * {@inheritDoc} */ public function setFormatter(FormatterInterface $formatter): HandlerInterface { if ($formatter instanceof ElasticaFormatter) { return parent::setFormatter($formatter); } throw new \InvalidArgumentException('ElasticaHandler is only compatible with ElasticaFormatter'); } /** * @return mixed[] */ public function getOptions(): array { return $this->options; } /** * {@inheritDoc} */ protected function getDefaultFormatter(): FormatterInterface { return new ElasticaFormatter($this->options['index'], $this->options['type']); } /** * {@inheritDoc} */ public function handleBatch(array $records): void { $documents = $this->getFormatter()->formatBatch($records); $this->bulkSend($documents); } /** * Use Elasticsearch bulk API to send list of documents * * @param Document[] $documents * * @throws \RuntimeException */ protected function bulkSend(array $documents): void { try { $this->client->addDocuments($documents); } catch (ExceptionInterface $e) { if (!$this->options['ignore_error']) { throw new \RuntimeException("Error sending messages to Elasticsearch", 0, $e); } } } } __halt_compiler();----SIGNATURE:----BWewqumPeN49pB5aYSGN6nVVKAyMIHlMSrdrNVnXWQHwJgr1CjVskIc0Wl9h/SIyrI0D9BZxMTKDahiT9OOCJBdsH6o416YABCAwOhoOytdF4XJ0R56xgRYTwl/HfRgJD2HXpoyHLfEjs0FTeSzvQcCk6CwYGLe1eiGrAP8b+jKObaI92KhjDWEqp7IwxO+2rOZySj4QhkhGQ5jcuRGcboVv4Q0GFbUBOOdXSUOntBGw+0ZG0AlIKYUDXMAaV8HDaBQlU64dMmWxUg9s05woZp1iE4y03WRAx9T5vcqIq1A3B3bBXTZmqN99W7wAcg0HXbViO/wjQtDt4hbfgTdutQqTKu2jOZexSaVNZbYRWERQC8gTX36H+n7A7TvDBEoFXhpZ0HHYfk501x0nN2gCJW58WFZGGeNRNOSufEZcxNB4izkR++mHZBK7ksWUdxuJ2dY41YyBDIrnTIqAUj28NcUQp5k1cJrgosh1XMpC+H7aRqs9qESJ9gg77ehcekyq6nr9upt1O+nsfPeG7o7U/4xev4px8z9qeYpDGxDGeMcsl7X9HhdeW4JEO8Pd/ttKFh/myxkuq+jfxS1pDauulLrMm2qDtVwTZ1vEiW3TFsB9rnMmOSnr2GmpZ/MH5ozOxevl3DZGBN759zEjgQ7gVa1sIlSvyFWvFvUrMeGSAbk=----ATTACHMENT:----MzIzNzk4NjE5NTU5NDU1IDk0ODAzNTcxMTA5NzE3OTggNTMwOTk3OTg5NTg3ODQ3OA==