@@ -97,11 +97,11 @@ class Logger {
9797 *
9898 * @since 1.0.0
9999 *
100- * @param string $path → path name to save file with logs
101- * @param string $filename → json file name that will save the logs
102- * @param int $logNumber → maximum number of logs to save to file
103- * @param string $ip → user ip. If you want to get to another library
104- * @param array $states → different states for logs
100+ * @param string $path → path name to save file with logs
101+ * @param string $filename → json file name that will save the logs
102+ * @param int $logNumber → maximum number of logs to save to file
103+ * @param string $ip → user ip. If you want to get to another library
104+ * @param array $states → different states for logs
105105 *
106106 * @return bool
107107 */
@@ -110,18 +110,18 @@ public function __construct($path = null, $filename = null, $logNumber = 200,
110110
111111 $ defaultPath = $ _SERVER ['DOCUMENT_ROOT ' ] . '/log/ ' ;
112112
113- static ::$ path = (!is_null ($ path )) ? $ path : $ defaultPath ;
114- static ::$ filename = (!is_null ($ filename )) ? $ filename : 'logs ' ;
115- static ::$ filename .= '.jsond ' ;
116- static ::$ filepath = static ::$ path . static ::$ filename ;
117- static ::$ logNumber = $ logNumber ;
113+ self ::$ path = (!is_null ($ path )) ? $ path : $ defaultPath ;
114+ self ::$ filename = (!is_null ($ filename )) ? $ filename : 'logs ' ;
115+ self ::$ filename .= '.jsond ' ;
116+ self ::$ filepath = self ::$ path . self ::$ filename ;
117+ self ::$ logNumber = $ logNumber ;
118118
119- static ::$ log ['ip ' ] = (isset ($ ip )) ? $ ip : $ _SERVER ['REMOTE_ADDR ' ];
120- static ::$ log ['uri ' ] = $ _SERVER ['REQUEST_URI ' ];
121- static ::$ log ['referer ' ] = $ _SERVER ['HTTP_REFERER ' ];
122- static ::$ log ['remote-port ' ] = $ _SERVER ['REMOTE_PORT ' ];
123- static ::$ log ['ip-server ' ] = $ _SERVER ['SERVER_ADDR ' ];
124- static ::$ log ['user-agent ' ] = $ _SERVER ['HTTP_USER_AGENT ' ];
119+ self ::$ log ['ip ' ] = (isset ($ ip )) ? $ ip : $ _SERVER ['REMOTE_ADDR ' ];
120+ self ::$ log ['uri ' ] = $ _SERVER ['REQUEST_URI ' ];
121+ self ::$ log ['referer ' ] = $ _SERVER ['HTTP_REFERER ' ];
122+ self ::$ log ['remote-port ' ] = $ _SERVER ['REMOTE_PORT ' ];
123+ self ::$ log ['ip-server ' ] = $ _SERVER ['SERVER_ADDR ' ];
124+ self ::$ log ['user-agent ' ] = $ _SERVER ['HTTP_USER_AGENT ' ];
125125
126126 $ defaultStates = [
127127 'is_active ' => 1 ,
@@ -132,11 +132,11 @@ public function __construct($path = null, $filename = null, $logNumber = 200,
132132 'fatal ' => 1 ,
133133 ];
134134
135- static ::$ states = (isset ($ states )) ? $ states : $ defaultStates ;
135+ self ::$ states = (isset ($ states )) ? $ states : $ defaultStates ;
136136
137137 register_shutdown_function (array ($ this , 'shutdown ' ));
138138
139- return (static ::$ states ['is_active ' ]) ? $ this ->_getLogs () : false ;
139+ return (self ::$ states ['is_active ' ]) ? $ this ->_getLogs () : false ;
140140 }
141141
142142 /**
@@ -149,25 +149,25 @@ public function __construct($path = null, $filename = null, $logNumber = 200,
149149 */
150150 private function _getLogs () {
151151
152- if (!is_dir (static ::$ path )) {
152+ if (!is_dir (self ::$ path )) {
153153
154- if (!mkdir (static ::$ path , 0755 , true )) {
154+ if (!mkdir (self ::$ path , 0755 , true )) {
155155
156- $ message = 'Could not create directory in: ' . static ::$ path ;
156+ $ message = 'Could not create directory in: ' . self ::$ path ;
157157
158158 throw new LoggerException ($ message , 706 );
159159 }
160160 }
161161
162- if (is_file (static ::$ filepath )) {
162+ if (is_file (self ::$ filepath )) {
163163
164- $ logs = file_get_contents (static ::$ filepath );
164+ $ logs = file_get_contents (self ::$ filepath );
165165
166- static ::$ logs = json_decode ($ logs , true );
166+ self ::$ logs = json_decode ($ logs , true );
167167
168- if (!count (static ::$ logs )) {
168+ if (!count (self ::$ logs )) {
169169
170- static ::save ('INFO ' , 1 , 200 , 'DEBUG [ON] ' , __LINE__ , __FILE__ );
170+ self ::save ('INFO ' , 1 , 200 , 'DEBUG [ON] ' , __LINE__ , __FILE__ );
171171 }
172172 }
173173
@@ -194,37 +194,37 @@ public static function save($type, $state, $code, $message,
194194
195195 $ type = strtolower ($ type );
196196
197- $ status = (isset (static ::$ states [$ type ])) ? static ::$ states [$ type ] : false ;
197+ $ status = (isset (self ::$ states [$ type ])) ? self ::$ states [$ type ] : false ;
198198
199- if (!isset ($ status ) || !$ status || !static ::$ states ['is_active ' ]) {
199+ if (!isset ($ status ) || !$ status || !self ::$ states ['is_active ' ]) {
200200
201201 return false ;
202202 }
203203
204- static ::$ log ['type ' ] = $ type ;
205- static ::$ log ['state ' ] = $ state ;
206- static ::$ log ['code ' ] = $ code ;
207- static ::$ log ['message ' ] = $ message ;
208- static ::$ log ['line ' ] = $ line ;
209- static ::$ log ['file ' ] = $ file ;
210- static ::$ log ['hour ' ] = date ('H:i:s ' );
211- static ::$ log ['date ' ] = date ('Y-m-d ' );
204+ self ::$ log ['type ' ] = $ type ;
205+ self ::$ log ['state ' ] = $ state ;
206+ self ::$ log ['code ' ] = $ code ;
207+ self ::$ log ['message ' ] = $ message ;
208+ self ::$ log ['line ' ] = $ line ;
209+ self ::$ log ['file ' ] = $ file ;
210+ self ::$ log ['hour ' ] = date ('H:i:s ' );
211+ self ::$ log ['date ' ] = date ('Y-m-d ' );
212212
213213 if (is_array ($ data )) {
214214
215215 foreach ($ data as $ key => $ value ) {
216216
217- static ::$ log [$ key ] = $ value ;
217+ self ::$ log [$ key ] = $ value ;
218218 }
219219 }
220220
221221 $ numLogs = 1 ;
222222
223- $ count = count (static ::$ logs );
223+ $ count = count (self ::$ logs );
224224
225- static ::$ logs [$ count ++] = static ::$ log ;
225+ self ::$ logs [$ count ++] = self ::$ log ;
226226
227- static ::$ counterLogs ++;
227+ self ::$ counterLogs ++;
228228
229229 return true ;
230230 }
@@ -240,32 +240,32 @@ public static function save($type, $state, $code, $message,
240240 */
241241 public static function storeLogs () {
242242
243- if (static ::$ counterLogs === 0 ) {
243+ if (self ::$ counterLogs === 0 ) {
244244
245245 return true ;
246246 }
247247
248- static ::_validateLogsNumber ();
248+ self ::_validateLogsNumber ();
249249
250- $ json = json_encode (static ::$ logs );
250+ $ json = json_encode (self ::$ logs );
251251
252- $ file = fopen (static ::$ filepath , 'w+ ' );
252+ $ file = fopen (self ::$ filepath , 'w+ ' );
253253
254254 if (!$ file ) {
255255
256- $ message = 'Could not create or open file in: ' . static ::$ filepath ;
256+ $ message = 'Could not create or open file in: ' . self ::$ filepath ;
257257
258258 throw new LoggerException ($ message , 707 );
259259 }
260260
261261 if (!fwrite ($ file , $ json )) {
262262
263- $ message = 'Could not write to file: ' . static ::$ filepath ;
263+ $ message = 'Could not write to file: ' . self ::$ filepath ;
264264
265265 throw new LoggerException ($ message , 708 );
266266 }
267267
268- static ::$ counterLogs = 0 ;
268+ self ::$ counterLogs = 0 ;
269269
270270 return true ;
271271 }
@@ -279,20 +279,20 @@ public static function storeLogs() {
279279 */
280280 private static function _validateLogsNumber () {
281281
282- $ logsCounter = count (static ::$ logs );
282+ $ logsCounter = count (self ::$ logs );
283283
284- if (static ::$ logNumber < $ logsCounter ) {
284+ if (self ::$ logNumber < $ logsCounter ) {
285285
286- $ logs = array_reverse (static ::$ logs );
286+ $ logs = array_reverse (self ::$ logs );
287287
288- $ conserve = static ::$ logNumber / 2 ;
288+ $ conserve = self ::$ logNumber / 2 ;
289289
290290 for ($ i =0 ; $ i < $ conserve ; $ i ++) {
291291
292292 $ conserveLogs [$ i ] = $ logs [$ i ];
293293 }
294294
295- static ::$ logs = array_reverse ($ conserveLogs );
295+ self ::$ logs = array_reverse ($ conserveLogs );
296296 }
297297
298298 return true ;
@@ -307,11 +307,11 @@ private static function _validateLogsNumber() {
307307 */
308308 public function shutdown () {
309309
310- if (count (static ::$ counterLogs ) > 0 ) {
310+ if (count (self ::$ counterLogs ) > 0 ) {
311311
312- if (isset (static ::$ states ['is_active ' ]) && static ::$ states ['is_active ' ]) {
312+ if (isset (self ::$ states ['is_active ' ]) && self ::$ states ['is_active ' ]) {
313313
314- static ::storeLogs ();
314+ self ::storeLogs ();
315315 }
316316 }
317317 }
0 commit comments