4 * This file is part of the Monolog package.
6 * (c) Jordi Boggiano <j.boggiano@seld.be>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Monolog\Formatter;
14 use Elastica\Document;
17 * Format a log message into an Elastica Document
19 * @author Jelle Vink <jelle.vink@gmail.com>
21 class ElasticaFormatter extends NormalizerFormatter
24 * @var string Elastic search index name
29 * @var string Elastic search document type
34 * @param string $index Elastic Search index name
35 * @param string $type Elastic Search document type
37 public function __construct($index, $type)
39 // elasticsearch requires a ISO 8601 format date with optional millisecond precision.
40 parent::__construct('Y-m-d\TH:i:s.uP');
42 $this->index = $index;
49 public function format(array $record)
51 $record = parent::format($record);
53 return $this->getDocument($record);
60 public function getIndex()
69 public function getType()
75 * Convert a log message into an Elastica Document
77 * @param array $record Log message
80 protected function getDocument($record)
82 $document = new Document();
83 $document->setData($record);
84 $document->setType($this->type);
85 $document->setIndex($this->index);