1 | <?php |
||
15 | class Logger { |
||
16 | |||
17 | const OFF = 0; |
||
18 | const ERROR = 400; |
||
19 | const WARNING = 300; |
||
20 | const NOTICE = 250; |
||
21 | const INFO = 200; |
||
22 | |||
23 | protected static $levels = array( |
||
24 | 0 => 'OFF', |
||
25 | 200 => 'INFO', |
||
26 | 250 => 'NOTICE', |
||
27 | 300 => 'WARNING', |
||
28 | 400 => 'ERROR', |
||
29 | ); |
||
30 | |||
31 | /** @var int $level The logging level */ |
||
32 | protected $level = self::ERROR; |
||
33 | |||
34 | /** @var bool $display Display to user? */ |
||
35 | protected $display = false; |
||
36 | |||
37 | /** @var \Elgg\PluginHooksService $hooks */ |
||
38 | protected $hooks; |
||
39 | |||
40 | /** @var \stdClass Global Elgg configuration */ |
||
41 | private $CONFIG; |
||
42 | |||
43 | /** |
||
44 | * Constructor |
||
45 | * |
||
46 | * @param \Elgg\PluginHooksService $hooks Hooks service |
||
47 | */ |
||
48 | 10 | public function __construct(\Elgg\PluginHooksService $hooks) { |
|
54 | |||
55 | /** |
||
56 | * Set the logging level |
||
57 | * |
||
58 | * @param int $level The logging level |
||
59 | * @return void |
||
60 | */ |
||
61 | 2 | public function setLevel($level) { |
|
69 | |||
70 | /** |
||
71 | * Get the current logging level |
||
72 | * |
||
73 | * @return int |
||
74 | */ |
||
75 | 1 | public function getLevel() { |
|
78 | |||
79 | /** |
||
80 | * Set whether the logging should be displayed to the user |
||
81 | * |
||
82 | * Whether data is actually displayed to the user depends on this setting |
||
83 | * and other factors such as whether we are generating a JavaScript or CSS |
||
84 | * file. |
||
85 | * |
||
86 | * @param bool $display Whether to display logging |
||
87 | * @return void |
||
88 | */ |
||
89 | public function setDisplay($display) { |
||
92 | |||
93 | /** |
||
94 | * Add a message to the log |
||
95 | * |
||
96 | * @param string $message The message to log |
||
97 | * @param int $level The logging level |
||
98 | * @return bool Whether the messages was logged |
||
99 | */ |
||
100 | 4 | public function log($message, $level = self::NOTICE) { |
|
118 | |||
119 | /** |
||
120 | * Log message at the ERROR level |
||
121 | * |
||
122 | * @param string $message The message to log |
||
123 | * @return bool |
||
124 | */ |
||
125 | public function error($message) { |
||
128 | |||
129 | /** |
||
130 | * Log message at the WARNING level |
||
131 | * |
||
132 | * @param string $message The message to log |
||
133 | * @return bool |
||
134 | */ |
||
135 | public function warn($message) { |
||
138 | |||
139 | /** |
||
140 | * Log message at the NOTICE level |
||
141 | * |
||
142 | * @param string $message The message to log |
||
143 | * @return bool |
||
144 | */ |
||
145 | public function notice($message) { |
||
148 | |||
149 | /** |
||
150 | * Log message at the INFO level |
||
151 | * |
||
152 | * @param string $message The message to log |
||
153 | * @return bool |
||
154 | */ |
||
155 | public function info($message) { |
||
158 | |||
159 | /** |
||
160 | * Dump data to log or screen |
||
161 | * |
||
162 | * @param mixed $data The data to log |
||
163 | * @param bool $display Whether to include this in the HTML page |
||
164 | * @return void |
||
165 | */ |
||
166 | public function dump($data, $display = true) { |
||
169 | |||
170 | /** |
||
171 | * Process logging data |
||
172 | * |
||
173 | * @param mixed $data The data to process |
||
174 | * @param bool $display Whether to display the data to the user. Otherwise log it. |
||
175 | * @param int $level The logging level for this data |
||
176 | * @return void |
||
177 | */ |
||
178 | 1 | protected function process($data, $display, $level) { |
|
219 | } |
||
220 | |||
221 |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.