scratch – Blame information for rev

Subversion Repositories:
Rev:
Rev Author Line No. Line
115 office 1 <?php
2  
3 /*
4 * This file is part of the Monolog package.
5 *
6 * (c) Jordi Boggiano <j.boggiano@seld.be>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11  
12 namespace Monolog\Formatter;
13  
14 use Elastica\Document;
15  
16 /**
17 * Format a log message into an Elastica Document
18 *
19 * @author Jelle Vink <jelle.vink@gmail.com>
20 */
21 class ElasticaFormatter extends NormalizerFormatter
22 {
23 /**
24 * @var string Elastic search index name
25 */
26 protected $index;
27  
28 /**
29 * @var string Elastic search document type
30 */
31 protected $type;
32  
33 /**
34 * @param string $index Elastic Search index name
35 * @param string $type Elastic Search document type
36 */
37 public function __construct($index, $type)
38 {
39 // elasticsearch requires a ISO 8601 format date with optional millisecond precision.
40 parent::__construct('Y-m-d\TH:i:s.uP');
41  
42 $this->index = $index;
43 $this->type = $type;
44 }
45  
46 /**
47 * {@inheritdoc}
48 */
49 public function format(array $record)
50 {
51 $record = parent::format($record);
52  
53 return $this->getDocument($record);
54 }
55  
56 /**
57 * Getter index
58 * @return string
59 */
60 public function getIndex()
61 {
62 return $this->index;
63 }
64  
65 /**
66 * Getter type
67 * @return string
68 */
69 public function getType()
70 {
71 return $this->type;
72 }
73  
74 /**
75 * Convert a log message into an Elastica Document
76 *
77 * @param array $record Log message
78 * @return Document
79 */
80 protected function getDocument($record)
81 {
82 $document = new Document();
83 $document->setData($record);
84 $document->setType($this->type);
85 $document->setIndex($this->index);
86  
87 return $document;
88 }
89 }