|
0
|
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\Handler; |
|
|
13 |
|
|
|
14 |
use Monolog\Logger; |
|
|
15 |
|
|
|
16 |
/** |
|
|
17 |
* Used for testing purposes. |
|
|
18 |
* |
|
|
19 |
* It records all records and gives you access to them for verification. |
|
|
20 |
* |
|
|
21 |
* @author Jordi Boggiano <j.boggiano@seld.be> |
|
|
22 |
*/ |
|
|
23 |
class TestHandler extends AbstractProcessingHandler |
|
|
24 |
{ |
|
|
25 |
protected $records = array(); |
|
|
26 |
protected $recordsByLevel = array(); |
|
|
27 |
|
|
|
28 |
public function getRecords() |
|
|
29 |
{ |
|
|
30 |
return $this->records; |
|
|
31 |
} |
|
|
32 |
|
|
|
33 |
public function hasAlert($record) |
|
|
34 |
{ |
|
|
35 |
return $this->hasRecord($record, Logger::ALERT); |
|
|
36 |
} |
|
|
37 |
|
|
|
38 |
public function hasCritical($record) |
|
|
39 |
{ |
|
|
40 |
return $this->hasRecord($record, Logger::CRITICAL); |
|
|
41 |
} |
|
|
42 |
|
|
|
43 |
public function hasError($record) |
|
|
44 |
{ |
|
|
45 |
return $this->hasRecord($record, Logger::ERROR); |
|
|
46 |
} |
|
|
47 |
|
|
|
48 |
public function hasWarning($record) |
|
|
49 |
{ |
|
|
50 |
return $this->hasRecord($record, Logger::WARNING); |
|
|
51 |
} |
|
|
52 |
|
|
|
53 |
public function hasInfo($record) |
|
|
54 |
{ |
|
|
55 |
return $this->hasRecord($record, Logger::INFO); |
|
|
56 |
} |
|
|
57 |
|
|
|
58 |
public function hasDebug($record) |
|
|
59 |
{ |
|
|
60 |
return $this->hasRecord($record, Logger::DEBUG); |
|
|
61 |
} |
|
|
62 |
|
|
|
63 |
public function hasAlertRecords() |
|
|
64 |
{ |
|
|
65 |
return isset($this->recordsByLevel[Logger::ALERT]); |
|
|
66 |
} |
|
|
67 |
|
|
|
68 |
public function hasCriticalRecords() |
|
|
69 |
{ |
|
|
70 |
return isset($this->recordsByLevel[Logger::CRITICAL]); |
|
|
71 |
} |
|
|
72 |
|
|
|
73 |
public function hasErrorRecords() |
|
|
74 |
{ |
|
|
75 |
return isset($this->recordsByLevel[Logger::ERROR]); |
|
|
76 |
} |
|
|
77 |
|
|
|
78 |
public function hasWarningRecords() |
|
|
79 |
{ |
|
|
80 |
return isset($this->recordsByLevel[Logger::WARNING]); |
|
|
81 |
} |
|
|
82 |
|
|
|
83 |
public function hasInfoRecords() |
|
|
84 |
{ |
|
|
85 |
return isset($this->recordsByLevel[Logger::INFO]); |
|
|
86 |
} |
|
|
87 |
|
|
|
88 |
public function hasDebugRecords() |
|
|
89 |
{ |
|
|
90 |
return isset($this->recordsByLevel[Logger::DEBUG]); |
|
|
91 |
} |
|
|
92 |
|
|
|
93 |
protected function hasRecord($record, $level) |
|
|
94 |
{ |
|
|
95 |
if (!isset($this->recordsByLevel[$level])) { |
|
|
96 |
return false; |
|
|
97 |
} |
|
|
98 |
|
|
|
99 |
if (is_array($record)) { |
|
|
100 |
$record = $record['message']; |
|
|
101 |
} |
|
|
102 |
|
|
|
103 |
foreach ($this->recordsByLevel[$level] as $rec) { |
|
|
104 |
if ($rec['message'] === $record) { |
|
|
105 |
return true; |
|
|
106 |
} |
|
|
107 |
} |
|
|
108 |
|
|
|
109 |
return false; |
|
|
110 |
} |
|
|
111 |
|
|
|
112 |
/** |
|
|
113 |
* {@inheritdoc} |
|
|
114 |
*/ |
|
|
115 |
protected function write(array $record) |
|
|
116 |
{ |
|
|
117 |
$this->recordsByLevel[$record['level']][] = $record; |
|
|
118 |
$this->records[] = $record; |
|
|
119 |
} |
|
|
120 |
} |