PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 4.7.0
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v4.7.0
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
← All changes | includes/class-updraft-logger.php +53 -34 3.2.7 → 4.7.0 View file →
@@ -13,29 +13,48 @@
13 13 * Class Updraft_Logger
14 14 */
15 15 class Updraft_Logger implements Updraft_Logger_Interface {
16 16
17 + /**
18 + * Array of loggers
19 + *
20 + * @var Updraft_Logger_Interface[]
21 + */
17 22 protected $_loggers = array();
18 23
19 24 /**
20 25 * Constructor method
21 26 *
22 - * @param Updraft_Logger_Interface $logger
27 + * @param Updraft_Logger_Interface|null $logger
23 28 */
24 - public function __construct(Updraft_Logger_Interface $logger = null) {
29 + public function __construct($logger = null) {
25 30 if (!empty($logger)) $this->_loggers = array($logger);
26 31 }
27 32
28 33 /**
34 + * Returns singleton instance object
35 + *
36 + * @return Updraft_Logger Returns `Updraft_Logger` object
37 + */
38 + public static function instance() {
39 + static $_instance = null;
40 + if (null === $_instance) {
41 + $_instance = new self();
42 + }
43 + return $_instance;
44 + }
45 +
46 + /**
29 47 * Add logger to loggers list
30 48 *
31 49 * @param Updraft_Logger_Interface $logger
50 + * @return false|void
32 51 */
33 - public function add_logger(Updraft_Logger_Interface $logger) {
52 + public function add_logger($logger) {
34 53 $logger_id = $logger_class = get_class($logger);
35 54
36 55 // don't add logger if it doesn't support multiple loggers.
37 - if (!empty($this->_loggers) && array_key_exists($logger_id, $this->_loggers) && false == $logger->is_allow_multiple()) return false;
56 + if (!empty($this->_loggers) && array_key_exists($logger_id, $this->_loggers) && false === $logger->is_allow_multiple()) return false;
38 57
39 58 $index = 0;
40 59
41 60 // get free id key.
@@ -60,13 +79,13 @@
60 79 * System is unusable.
61 80 *
62 81 * @param string $message
63 82 * @param array $context
64 - * @return null
83 + * @return void
65 84 */
66 - public function emergency($message, array $context = array()) {
85 + public function emergency($message, $context = array()) {
67 86
68 - if (empty($this->_loggers)) return false;
87 + if (empty($this->_loggers)) return;
69 88
70 89 foreach ($this->_loggers as $logger) {
71 90 $logger->emergency($message, $context);
72 91 }
@@ -80,13 +99,13 @@
80 99 * trigger the SMS alerts and wake you up.
81 100 *
82 101 * @param string $message
83 102 * @param array $context
84 - * @return null
103 + * @return void
85 104 */
86 - public function alert($message, array $context = array()) {
105 + public function alert($message, $context = array()) {
87 106
88 - if (empty($this->_loggers)) return false;
107 + if (empty($this->_loggers)) return;
89 108
90 109 foreach ($this->_loggers as $logger) {
91 110 $logger->alert($message, $context);
92 111 }
@@ -99,13 +118,13 @@
99 118 * Example: Application component unavailable, unexpected exception.
100 119 *
101 120 * @param string $message
102 121 * @param array $context
103 - * @return null
122 + * @return void
104 123 */
105 - public function critical($message, array $context = array()) {
124 + public function critical($message, $context = array()) {
106 125
107 - if (empty($this->_loggers)) return false;
126 + if (empty($this->_loggers)) return;
108 127
109 128 foreach ($this->_loggers as $logger) {
110 129 $logger->critical($message, $context);
111 130 }
@@ -117,13 +136,13 @@
117 136 * be logged and monitored.
118 137 *
119 138 * @param string $message
120 139 * @param array $context
121 - * @return null
140 + * @return void
122 141 */
123 - public function error($message, array $context = array()) {
142 + public function error($message, $context = array()) {
124 143
125 - if (empty($this->_loggers)) return false;
144 + if (empty($this->_loggers)) return;
126 145
127 146 foreach ($this->_loggers as $logger) {
128 147 $logger->error($message, $context);
129 148 }
@@ -137,13 +156,13 @@
137 156 * that are not necessarily wrong.
138 157 *
139 158 * @param string $message
140 159 * @param array $context
141 - * @return null
160 + * @return void
142 161 */
143 - public function warning($message, array $context = array()) {
162 + public function warning($message, $context = array()) {
144 163
145 - if (empty($this->_loggers)) return false;
164 + if (empty($this->_loggers)) return;
146 165
147 166 foreach ($this->_loggers as $logger) {
148 167 $logger->warning($message, $context);
149 168 }
@@ -154,13 +173,13 @@
154 173 * Normal but significant events.
155 174 *
156 175 * @param string $message
157 176 * @param array $context
158 - * @return null
177 + * @return void
159 178 */
160 - public function notice($message, array $context = array()) {
179 + public function notice($message, $context = array()) {
161 180
162 - if (empty($this->_loggers)) return false;
181 + if (empty($this->_loggers)) return;
163 182
164 183 foreach ($this->_loggers as $logger) {
165 184 $logger->notice($message, $context);
166 185 }
@@ -173,13 +192,13 @@
173 192 * Example: User logs in, SQL logs.
174 193 *
175 194 * @param string $message
176 195 * @param array $context
177 - * @return null
196 + * @return void
178 197 */
179 - public function info($message, array $context = array()) {
198 + public function info($message, $context = array()) {
180 199
181 - if (empty($this->_loggers)) return false;
200 + if (empty($this->_loggers)) return;
182 201
183 202 foreach ($this->_loggers as $logger) {
184 203 $logger->info($message, $context);
185 204 }
@@ -190,13 +209,13 @@
190 209 * Detailed debug information.
191 210 *
192 211 * @param string $message
193 212 * @param array $context
194 - * @return null
213 + * @return void
195 214 */
196 - public function debug($message, array $context = array()) {
215 + public function debug($message, $context = array()) {
197 216
198 - if (empty($this->_loggers)) return false;
217 + if (empty($this->_loggers)) return;
199 218
200 219 foreach ($this->_loggers as &$logger) {
201 220 $logger->debug($message, $context);
202 221 }
@@ -205,16 +224,16 @@
205 224
206 225 /**
207 226 * Logs with an arbitrary level.
208 227 *
209 - * @param mixed $level
210 - * @param string $message
211 - * @param array $context
212 - * @return null
228 + * @param string $message
229 + * @param mixed $level
230 + * @param array $context
231 + * @return void
213 232 */
214 - public function log($level, $message, array $context = array()) {
233 + public function log($message, $level, $context = array()) {
215 234
216 - if (empty($this->_loggers)) return false;
235 + if (empty($this->_loggers)) return;
217 236
218 237 foreach ($this->_loggers as $logger) {
219 238 $logger->log($message, $level, $context);
220 239 }