@@ -97,11 +97,11 @@ class Logger {
97
97
*
98
98
* @since 1.0.0
99
99
*
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
105
105
*
106
106
* @return bool
107
107
*/
@@ -110,18 +110,18 @@ public function __construct($path = null, $filename = null, $logNumber = 200,
110
110
111
111
$ defaultPath = $ _SERVER ['DOCUMENT_ROOT ' ] . '/log/ ' ;
112
112
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 ;
118
118
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 ' ];
125
125
126
126
$ defaultStates = [
127
127
'is_active ' => 1 ,
@@ -132,11 +132,11 @@ public function __construct($path = null, $filename = null, $logNumber = 200,
132
132
'fatal ' => 1 ,
133
133
];
134
134
135
- static ::$ states = (isset ($ states )) ? $ states : $ defaultStates ;
135
+ self ::$ states = (isset ($ states )) ? $ states : $ defaultStates ;
136
136
137
137
register_shutdown_function (array ($ this , 'shutdown ' ));
138
138
139
- return (static ::$ states ['is_active ' ]) ? $ this ->_getLogs () : false ;
139
+ return (self ::$ states ['is_active ' ]) ? $ this ->_getLogs () : false ;
140
140
}
141
141
142
142
/**
@@ -149,25 +149,25 @@ public function __construct($path = null, $filename = null, $logNumber = 200,
149
149
*/
150
150
private function _getLogs () {
151
151
152
- if (!is_dir (static ::$ path )) {
152
+ if (!is_dir (self ::$ path )) {
153
153
154
- if (!mkdir (static ::$ path , 0755 , true )) {
154
+ if (!mkdir (self ::$ path , 0755 , true )) {
155
155
156
- $ message = 'Could not create directory in: ' . static ::$ path ;
156
+ $ message = 'Could not create directory in: ' . self ::$ path ;
157
157
158
158
throw new LoggerException ($ message , 706 );
159
159
}
160
160
}
161
161
162
- if (is_file (static ::$ filepath )) {
162
+ if (is_file (self ::$ filepath )) {
163
163
164
- $ logs = file_get_contents (static ::$ filepath );
164
+ $ logs = file_get_contents (self ::$ filepath );
165
165
166
- static ::$ logs = json_decode ($ logs , true );
166
+ self ::$ logs = json_decode ($ logs , true );
167
167
168
- if (!count (static ::$ logs )) {
168
+ if (!count (self ::$ logs )) {
169
169
170
- static ::save ('INFO ' , 1 , 200 , 'DEBUG [ON] ' , __LINE__ , __FILE__ );
170
+ self ::save ('INFO ' , 1 , 200 , 'DEBUG [ON] ' , __LINE__ , __FILE__ );
171
171
}
172
172
}
173
173
@@ -194,37 +194,37 @@ public static function save($type, $state, $code, $message,
194
194
195
195
$ type = strtolower ($ type );
196
196
197
- $ status = (isset (static ::$ states [$ type ])) ? static ::$ states [$ type ] : false ;
197
+ $ status = (isset (self ::$ states [$ type ])) ? self ::$ states [$ type ] : false ;
198
198
199
- if (!isset ($ status ) || !$ status || !static ::$ states ['is_active ' ]) {
199
+ if (!isset ($ status ) || !$ status || !self ::$ states ['is_active ' ]) {
200
200
201
201
return false ;
202
202
}
203
203
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 ' );
212
212
213
213
if (is_array ($ data )) {
214
214
215
215
foreach ($ data as $ key => $ value ) {
216
216
217
- static ::$ log [$ key ] = $ value ;
217
+ self ::$ log [$ key ] = $ value ;
218
218
}
219
219
}
220
220
221
221
$ numLogs = 1 ;
222
222
223
- $ count = count (static ::$ logs );
223
+ $ count = count (self ::$ logs );
224
224
225
- static ::$ logs [$ count ++] = static ::$ log ;
225
+ self ::$ logs [$ count ++] = self ::$ log ;
226
226
227
- static ::$ counterLogs ++;
227
+ self ::$ counterLogs ++;
228
228
229
229
return true ;
230
230
}
@@ -240,32 +240,32 @@ public static function save($type, $state, $code, $message,
240
240
*/
241
241
public static function storeLogs () {
242
242
243
- if (static ::$ counterLogs === 0 ) {
243
+ if (self ::$ counterLogs === 0 ) {
244
244
245
245
return true ;
246
246
}
247
247
248
- static ::_validateLogsNumber ();
248
+ self ::_validateLogsNumber ();
249
249
250
- $ json = json_encode (static ::$ logs );
250
+ $ json = json_encode (self ::$ logs );
251
251
252
- $ file = fopen (static ::$ filepath , 'w+ ' );
252
+ $ file = fopen (self ::$ filepath , 'w+ ' );
253
253
254
254
if (!$ file ) {
255
255
256
- $ message = 'Could not create or open file in: ' . static ::$ filepath ;
256
+ $ message = 'Could not create or open file in: ' . self ::$ filepath ;
257
257
258
258
throw new LoggerException ($ message , 707 );
259
259
}
260
260
261
261
if (!fwrite ($ file , $ json )) {
262
262
263
- $ message = 'Could not write to file: ' . static ::$ filepath ;
263
+ $ message = 'Could not write to file: ' . self ::$ filepath ;
264
264
265
265
throw new LoggerException ($ message , 708 );
266
266
}
267
267
268
- static ::$ counterLogs = 0 ;
268
+ self ::$ counterLogs = 0 ;
269
269
270
270
return true ;
271
271
}
@@ -279,20 +279,20 @@ public static function storeLogs() {
279
279
*/
280
280
private static function _validateLogsNumber () {
281
281
282
- $ logsCounter = count (static ::$ logs );
282
+ $ logsCounter = count (self ::$ logs );
283
283
284
- if (static ::$ logNumber < $ logsCounter ) {
284
+ if (self ::$ logNumber < $ logsCounter ) {
285
285
286
- $ logs = array_reverse (static ::$ logs );
286
+ $ logs = array_reverse (self ::$ logs );
287
287
288
- $ conserve = static ::$ logNumber / 2 ;
288
+ $ conserve = self ::$ logNumber / 2 ;
289
289
290
290
for ($ i =0 ; $ i < $ conserve ; $ i ++) {
291
291
292
292
$ conserveLogs [$ i ] = $ logs [$ i ];
293
293
}
294
294
295
- static ::$ logs = array_reverse ($ conserveLogs );
295
+ self ::$ logs = array_reverse ($ conserveLogs );
296
296
}
297
297
298
298
return true ;
@@ -307,11 +307,11 @@ private static function _validateLogsNumber() {
307
307
*/
308
308
public function shutdown () {
309
309
310
- if (count (static ::$ counterLogs ) > 0 ) {
310
+ if (count (self ::$ counterLogs ) > 0 ) {
311
311
312
- if (isset (static ::$ states ['is_active ' ]) && static ::$ states ['is_active ' ]) {
312
+ if (isset (self ::$ states ['is_active ' ]) && self ::$ states ['is_active ' ]) {
313
313
314
- static ::storeLogs ();
314
+ self ::storeLogs ();
315
315
}
316
316
}
317
317
}
0 commit comments