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-file-logger.php +25 -24 3.3.1 → 4.7.0 View file →
@@ -25,9 +25,9 @@
25 25
26 26 /**
27 27 * Returns logger description
28 28 *
29 - * @return string|void
29 + * @return string
30 30 */
31 31 public function get_description() {
32 32 return __('Log events into a log file', 'wp-optimize');
33 33 }
@@ -36,11 +36,11 @@
36 36 * Emergency message
37 37 *
38 38 * @param string $message
39 39 * @param array $context
40 - * @return null|void
40 + * @return void
41 41 */
42 - public function emergency($message, array $context = array()) {
42 + public function emergency($message, $context = array()) {
43 43 $this->log($message, Updraft_Log_Levels::EMERGENCY, $context);
44 44 }
45 45
46 46 /**
@@ -47,11 +47,11 @@
47 47 * Alert message
48 48 *
49 49 * @param string $message
50 50 * @param array $context
51 - * @return null|void
51 + * @return void
52 52 */
53 - public function alert($message, array $context = array()) {
53 + public function alert($message, $context = array()) {
54 54 $this->log($message, Updraft_Log_Levels::ALERT, $context);
55 55 }
56 56
57 57 /**
@@ -58,11 +58,11 @@
58 58 * Critical message
59 59 *
60 60 * @param string $message
61 61 * @param array $context
62 - * @return null|void
62 + * @return void
63 63 */
64 - public function critical($message, array $context = array()) {
64 + public function critical($message, $context = array()) {
65 65 $this->log($message, Updraft_Log_Levels::CRITICAL, $context);
66 66 }
67 67
68 68 /**
@@ -69,11 +69,11 @@
69 69 * Error message
70 70 *
71 71 * @param string $message
72 72 * @param array $context
73 - * @return null|void
73 + * @return void
74 74 */
75 - public function error($message, array $context = array()) {
75 + public function error($message, $context = array()) {
76 76 $this->log($message, Updraft_Log_Levels::ERROR, $context);
77 77 }
78 78
79 79 /**
@@ -80,11 +80,11 @@
80 80 * Warning message
81 81 *
82 82 * @param string $message
83 83 * @param array $context
84 - * @return null|void
84 + * @return void
85 85 */
86 - public function warning($message, array $context = array()) {
86 + public function warning($message, $context = array()) {
87 87 $this->log($message, Updraft_Log_Levels::WARNING, $context);
88 88 }
89 89
90 90 /**
@@ -91,11 +91,11 @@
91 91 * Notice message
92 92 *
93 93 * @param string $message
94 94 * @param array $context
95 - * @return null|void
95 + * @return void
96 96 */
97 - public function notice($message, array $context = array()) {
97 + public function notice($message, $context = array()) {
98 98 $this->log($message, Updraft_Log_Levels::NOTICE, $context);
99 99 }
100 100
101 101 /**
@@ -102,11 +102,11 @@
102 102 * Info message
103 103 *
104 104 * @param string $message
105 105 * @param array $context
106 - * @return null|void
106 + * @return void
107 107 */
108 - public function info($message, array $context = array()) {
108 + public function info($message, $context = array()) {
109 109 $this->log($message, Updraft_Log_Levels::INFO, $context);
110 110 }
111 111
112 112 /**
@@ -113,11 +113,11 @@
113 113 * Debug message
114 114 *
115 115 * @param string $message
116 116 * @param array $context
117 - * @return null|void
117 + * @return void
118 118 */
119 - public function debug($message, array $context = array()) {
119 + public function debug($message, $context = array()) {
120 120 $this->log($message, Updraft_Log_Levels::DEBUG, $context);
121 121 }
122 122
123 123 /**
@@ -125,18 +125,18 @@
125 125 *
126 126 * @param string $message
127 127 * @param mixed $level
128 128 * @param array $context
129 - * @return null|void
129 + * @return void
130 130 */
131 - public function log($message, $level, array $context = array()) {
131 + public function log($message, $level, $context = array()) {
132 132
133 - if (!$this->is_enabled()) return false;
133 + if (!$this->is_enabled()) return;
134 134
135 - $message = sprintf("[%s : %s] - %s \n", date("Y-m-d H:i:s"), Updraft_Log_Levels::to_text($level), $this->interpolate($message, $context));
135 + $message = sprintf("[%s : %s] - %s \n", gmdate("Y-m-d H:i:s"), Updraft_Log_Levels::to_text($level), $this->interpolate($message, $context));
136 136
137 - if (false == file_put_contents($this->logfile, $message, FILE_APPEND)) {
138 - error_log($message);
137 + if (false === file_put_contents($this->logfile, $message, FILE_APPEND)) {
138 + error_log($message); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- Using for debugging purpose
139 139 }
140 140 }
141 141
142 142 /**
@@ -156,8 +156,9 @@
156 156 // phpcs:disable
157 157
158 158 // We ignore a few lines here to avoid warnings on file operations
159 159 // WP.VIP does not like us writing directly to the filesystem
160 + if (!is_file($this->logfile)) return false;
160 161 $logfile_handle = fopen($this->logfile, "r");
161 162 if (false === $logfile_handle) return false;
162 163 $temp_file = fopen(preg_replace("/\.log$/", "-temp.log", $this->logfile), "a");
163 164
@@ -162,9 +163,9 @@
162 163 $temp_file = fopen(preg_replace("/\.log$/", "-temp.log", $this->logfile), "a");
163 164
164 165 // Stream is the preferred way because of potentially large file sizes
165 166 while ($line = stream_get_line($logfile_handle, 1024 * 1024, "\n")) {
166 -
167 +
167 168 $pattern = '/(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})/';
168 169 if (preg_match($pattern, $line, $matches)) {
169 170 if (strtotime($matches[0]) > $prune_period) {
170 171 fwrite($temp_file, $line."\n");