'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:----R+ZpGp6doJVlucnYQjZhn88PQyn2oSf5sTbYMuLP1mYYmWXPpgIueNoBzf9EdEvuOuKUgabAa3rjPU6L8PxisNbsgRLyHt5JTgtN0NhORT6sqSABeyUHsH0OvvEqhieQNH8vc1VrsA5bnqY4SXnvz+LxHRn0kOUguWBvAgqgmZIk0sE8wkU8ph/7m9UaIVNmdf1vCR5AckUjXYS2lHNMuR6K0wcWWz3c6SP6tKGFsyuDWKcJ2qb1kTx8LMI69H1irAN8l7cK2P6bqXh13sMa5sqlr4MQ7RH4d2alMOa6XFUMcoS9rzaNs/AhhiGAx6r2/Jct8pw+fYOt5TkD/3A+OHp1Bse6VV3CDX29HTkEl0nAmYUIIZdKIrKFNduC4QBy69Z2nnlODtSZvi8A92kGdo4oD0icvvEp9zFxm8obGuzCtmadxnjAd74I/j8ZMXM4Mx2PtlbqVd1BUmekMuoCuGtE3dVSBoGZRQP0oc3+T5Y94FtIMF7ygOeHQrxZwQMTZr7oXvOg0SLeU41WAbT6uE3+XlXM7W5apHvujsVjI3jK3hE9v+pCVamyImOyrecPrEPvt506foFBW2QsNpHwiQ5/fEgC0z0Japkt20Pc1c1DE8iHsTA6VH16Y5sENy8taFX2ZToGz3/597pBadVvfj0G+iz5oVly45IrLj9IF4Y=----ATTACHMENT:----NTc1NjIwNDY1MTUxNjc2NyA0NzU1MTQzMTAyMTQwNzI1IDc2NzgyMzUxOTc2MDQ1MDQ=