ElasticaLogger   A
last analyzed

Complexity

Total Complexity 22

Size/Duplication

Total Lines 143
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 22
lcom 1
cbo 1
dl 0
loc 143
ccs 56
cts 56
cp 1
rs 10
c 0
b 0
f 0

12 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getNbQueries() 0 4 1
A getQueries() 0 4 1
A debug() 0 10 3
A emergency() 0 6 2
A alert() 0 6 2
A critical() 0 6 2
A error() 0 6 2
A warning() 0 6 2
A notice() 0 6 2
A info() 0 6 2
A log() 0 6 2
1
<?php
2
3
namespace GBProd\ElasticaBundle\Logger;
4
5
use Psr\Log\LoggerInterface;
6
7
/**
8
 * Logger for Elastica
9
 *
10
 * @author GBProd <[email protected]>
11
 */
12
class ElasticaLogger implements LoggerInterface
13
{
14
    /**
15
     * @var LoggerInterface
16
     */
17
    protected $logger;
18
19
    /**
20
     * @var array
21
     */
22
    protected $queries = array();
23
24
    /**
25
     * @var boolean
26
     */
27
    protected $debug;
28
29
    /**
30
     * Constructor.
31
     *
32
     * @param LoggerInterface|null $logger The Symfony logger
33
     * @param boolean              $debug
34
     */
35 26
    public function __construct(LoggerInterface $logger = null, $debug = false)
36
    {
37 26
        $this->logger = $logger;
38 26
        $this->debug  = $debug;
39 26
    }
40
41
    /**
42
     * Returns the number of queries that have been logged.
43
     *
44
     * @return integer The number of queries logged
45
     */
46 4
    public function getNbQueries()
47
    {
48 4
        return count($this->queries);
49
    }
50
51
    /**
52
     * Returns a human-readable array of queries logged.
53
     *
54
     * @return array An array of queries
55
     */
56 2
    public function getQueries()
57
    {
58 2
        return $this->queries;
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64 5
    public function debug($message, array $context = array())
65
    {
66 5
        if ($this->debug) {
67 2
            $this->queries[] = $context;
68 2
        }
69
70 5
        if ($this->logger) {
71 1
            $this->logger->debug($message, $context);
72 1
        }
73 5
    }
74
75
    /**
76
     * {@inheritdoc}
77
     */
78 2
    public function emergency($message, array $context = array())
79
    {
80 2
        if ($this->logger) {
81 1
            $this->logger->emergency($message, $context);
82 1
        }
83 2
    }
84
85
    /**
86
     * {@inheritdoc}
87
     */
88 2
    public function alert($message, array $context = array())
89
    {
90 2
        if ($this->logger) {
91 1
            $this->logger->alert($message, $context);
92 1
        }
93 2
    }
94
95
    /**
96
     * {@inheritdoc}
97
     */
98 2
    public function critical($message, array $context = array())
99
    {
100 2
        if ($this->logger) {
101 1
            $this->logger->critical($message, $context);
102 1
        }
103 2
    }
104
105
    /**
106
     * {@inheritdoc}
107
     */
108 2
    public function error($message, array $context = array())
109
    {
110 2
        if ($this->logger) {
111 1
            $this->logger->error($message, $context);
112 1
        }
113 2
    }
114
115
    /**
116
     * {@inheritdoc}
117
     */
118 2
    public function warning($message, array $context = array())
119
    {
120 2
        if ($this->logger) {
121 1
            $this->logger->warning($message, $context);
122 1
        }
123 2
    }
124
125
    /**
126
     * {@inheritdoc}
127
     */
128 2
    public function notice($message, array $context = array())
129
    {
130 2
        if ($this->logger) {
131 1
            $this->logger->notice($message, $context);
132 1
        }
133 2
    }
134
135
    /**
136
     * {@inheritdoc}
137
     */
138 2
    public function info($message, array $context = array())
139
    {
140 2
        if ($this->logger) {
141 1
            $this->logger->info($message, $context);
142 1
        }
143 2
    }
144
145
    /**
146
     * {@inheritdoc}
147
     */
148 2
    public function log($level, $message, array $context = array())
149
    {
150 2
        if ($this->logger) {
151 1
            $this->logger->log($level, $message, $context);
152 1
        }
153 2
    }
154
}
155