This repository has been archived by the owner on Jan 21, 2020. It is now read-only.
/
Debug.php
executable file
·81 lines (70 loc) · 1.9 KB
/
Debug.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
<?php
class CM_Debug {
/** @var array */
private $_stats = array();
/** @var bool */
private $_enabled;
/**
* @param bool $enabled
*/
public function __construct($enabled) {
$this->_enabled = (bool) $enabled;
}
/**
* @return array[]
*/
public function getStats() {
return $this->_stats;
}
/**
* @param string $key
* @param string|string[] $value
*/
public function incStats($key, $value) {
if (!$this->_enabled) {
return;
}
if (!array_key_exists($key, $this->_stats)) {
$this->_stats[$key] = array();
}
$this->_stats[$key][] = $value;
}
/**
* @return bool
*/
public function isEnabled() {
return $this->_enabled;
}
/**
* @param bool $state
*/
public function setEnabled($state) {
$this->_enabled = $state;
}
/**
* @deprecated use CM_Service_Manager::getInstance()->getDebug()
* @return CM_Debug
*/
public static function getInstance() {
return CM_Service_Manager::getInstance()->getDebug();
}
/**
* @param string $message
* @param array|null $extra
*/
public static function log($message, array $extra = null) {
$message = (string) $message;
$trace = debug_backtrace();
$className = 'none';
$functionName = 'none';
if (isset($trace[1])) {
$className = isset($trace[1]['class']) ? $trace[1]['class'] : $className;
$functionName = isset($trace[1]['function']) ? $trace[1]['function'] : $functionName;
}
$context = new CM_Log_Context();
if (null !== $extra) {
$context->setExtra($extra);
}
CM_Service_Manager::getInstance()->getLogger()->debug(sprintf('%s:%s - %s', $className, $functionName, $message), $context);
}
}