PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 3.2.21
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v3.2.21
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
wp-optimize / includes / class-updraft-logger.php

class-updraft-logger.php in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 3.2.21, at includes/class-updraft-logger.php

237 lines 4.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('ABSPATH')) die('No direct access allowed');
4
5 require_once('class-updraft-logger-interface.php');
6 require_once('class-updraft-log-levels.php');
7 require_once('class-updraft-abstract-logger.php');
8 require_once('class-updraft-logger.php');
9
10 if (class_exists('Updraft_Logger')) return;
11
12 /**
13 * Class Updraft_Logger
14 */
15 class Updraft_Logger implements Updraft_Logger_Interface {
16
17 protected $_loggers = array();
18
19 /**
20 * Constructor method
21 *
22 * @param Updraft_Logger_Interface $logger
23 */
24 public function __construct(Updraft_Logger_Interface $logger = null) {
25 if (!empty($logger)) $this->_loggers = array($logger);
26 }
27
28 /**
29 * Returns singleton instance object
30 *
31 * @return Updraft_Logger Returns `Updraft_Logger` object
32 */
33 public static function instance() {
34 static $_instance = null;
35 if (null === $_instance) {
36 $_instance = new self();
37 }
38 return $_instance;
39 }
40
41 /**
42 * Add logger to loggers list
43 *
44 * @param Updraft_Logger_Interface $logger
45 */
46 public function add_logger(Updraft_Logger_Interface $logger) {
47 $logger_id = $logger_class = get_class($logger);
48
49 // don't add logger if it doesn't support multiple loggers.
50 if (!empty($this->_loggers) && array_key_exists($logger_id, $this->_loggers) && false == $logger->is_allow_multiple()) return false;
51
52 $index = 0;
53
54 // get free id key.
55 while (array_key_exists($logger_id, $this->_loggers)) {
56 $index++;
57 $logger_id = $logger_class.'_'.$index;
58 }
59
60 $this->_loggers[$logger_id] = $logger;
61 }
62
63 /**
64 * Return list of loggers
65 *
66 * @return array
67 */
68 public function get_loggers() {
69 return $this->_loggers;
70 }
71
72 /**
73 * System is unusable.
74 *
75 * @param string $message
76 * @param array $context
77 * @return null
78 */
79 public function emergency($message, array $context = array()) {
80
81 if (empty($this->_loggers)) return false;
82
83 foreach ($this->_loggers as $logger) {
84 $logger->emergency($message, $context);
85 }
86
87 }
88
89 /**
90 * Action must be taken immediately.
91 *
92 * Example: Entire website down, database unavailable, etc. This should
93 * trigger the SMS alerts and wake you up.
94 *
95 * @param string $message
96 * @param array $context
97 * @return null
98 */
99 public function alert($message, array $context = array()) {
100
101 if (empty($this->_loggers)) return false;
102
103 foreach ($this->_loggers as $logger) {
104 $logger->alert($message, $context);
105 }
106
107 }
108
109 /**
110 * Critical conditions.
111 *
112 * Example: Application component unavailable, unexpected exception.
113 *
114 * @param string $message
115 * @param array $context
116 * @return null
117 */
118 public function critical($message, array $context = array()) {
119
120 if (empty($this->_loggers)) return false;
121
122 foreach ($this->_loggers as $logger) {
123 $logger->critical($message, $context);
124 }
125
126 }
127
128 /**
129 * Runtime errors that do not require immediate action but should typically
130 * be logged and monitored.
131 *
132 * @param string $message
133 * @param array $context
134 * @return null
135 */
136 public function error($message, array $context = array()) {
137
138 if (empty($this->_loggers)) return false;
139
140 foreach ($this->_loggers as $logger) {
141 $logger->error($message, $context);
142 }
143
144 }
145
146 /**
147 * Exceptional occurrences that are not errors.
148 *
149 * Example: Use of deprecated APIs, poor use of an API, undesirable things
150 * that are not necessarily wrong.
151 *
152 * @param string $message
153 * @param array $context
154 * @return null
155 */
156 public function warning($message, array $context = array()) {
157
158 if (empty($this->_loggers)) return false;
159
160 foreach ($this->_loggers as $logger) {
161 $logger->warning($message, $context);
162 }
163
164 }
165
166 /**
167 * Normal but significant events.
168 *
169 * @param string $message
170 * @param array $context
171 * @return null
172 */
173 public function notice($message, array $context = array()) {
174
175 if (empty($this->_loggers)) return false;
176
177 foreach ($this->_loggers as $logger) {
178 $logger->notice($message, $context);
179 }
180
181 }
182
183 /**
184 * Interesting events.
185 *
186 * Example: User logs in, SQL logs.
187 *
188 * @param string $message
189 * @param array $context
190 * @return null
191 */
192 public function info($message, array $context = array()) {
193
194 if (empty($this->_loggers)) return false;
195
196 foreach ($this->_loggers as $logger) {
197 $logger->info($message, $context);
198 }
199
200 }
201
202 /**
203 * Detailed debug information.
204 *
205 * @param string $message
206 * @param array $context
207 * @return null
208 */
209 public function debug($message, array $context = array()) {
210
211 if (empty($this->_loggers)) return false;
212
213 foreach ($this->_loggers as &$logger) {
214 $logger->debug($message, $context);
215 }
216
217 }
218
219 /**
220 * Logs with an arbitrary level.
221 *
222 * @param mixed $level
223 * @param string $message
224 * @param array $context
225 * @return null
226 */
227 public function log($level, $message, array $context = array()) {
228
229 if (empty($this->_loggers)) return false;
230
231 foreach ($this->_loggers as $logger) {
232 $logger->log($message, $level, $context);
233 }
234
235 }
236 }
237