forked from Seldaek/monolog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ZendMonitorHandler.php
97 lines (88 loc) · 2.27 KB
/
ZendMonitorHandler.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php declare(strict_types=1);
/*
* This file is part of the Monolog package.
*
* (c) Jordi Boggiano <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Monolog\Handler;
use Monolog\Formatter\FormatterInterface;
use Monolog\Formatter\NormalizerFormatter;
use Monolog\Logger;
/**
* Handler sending logs to Zend Monitor
*
* @author Christian Bergau <[email protected]>
*/
class ZendMonitorHandler extends AbstractProcessingHandler
{
/**
* Monolog level / ZendMonitor Custom Event priority map
*
* @var array
*/
protected $levelMap = [
Logger::DEBUG => 1,
Logger::INFO => 2,
Logger::NOTICE => 3,
Logger::WARNING => 4,
Logger::ERROR => 5,
Logger::CRITICAL => 6,
Logger::ALERT => 7,
Logger::EMERGENCY => 0,
];
/**
* Construct
*
* @param int $level
* @param bool $bubble
* @throws MissingExtensionException
*/
public function __construct($level = Logger::DEBUG, $bubble = true)
{
if (!function_exists('zend_monitor_custom_event')) {
throw new MissingExtensionException('You must have Zend Server installed in order to use this handler');
}
parent::__construct($level, $bubble);
}
/**
* {@inheritdoc}
*/
protected function write(array $record)
{
$this->writeZendMonitorCustomEvent(
$this->levelMap[$record['level']],
$record['message'],
$record['formatted']
);
}
/**
* Write a record to Zend Monitor
*
* @param int $level
* @param string $message
* @param array $formatted
*/
protected function writeZendMonitorCustomEvent($level, $message, $formatted)
{
zend_monitor_custom_event($level, $message, $formatted);
}
/**
* {@inheritdoc}
*/
public function getDefaultFormatter(): FormatterInterface
{
return new NormalizerFormatter();
}
/**
* Get the level map
*
* @return array
*/
public function getLevelMap()
{
return $this->levelMap;
}
}