| Conditions | 7 |
| Paths | 18 |
| Total Lines | 38 |
| Code Lines | 22 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 30 | public function log() |
||
| 31 | {
|
||
| 32 | if(app()->has('track.path')){
|
||
| 33 | $trackPath = app()->get('track.path');
|
||
| 34 | $logger = $trackPath($this->argument); |
||
| 35 | } |
||
| 36 | else{
|
||
| 37 | $logger = app()->path()->appLog().''.DIRECTORY_SEPARATOR.''.date('Y').''.DIRECTORY_SEPARATOR.''.date('m').''.DIRECTORY_SEPARATOR.''.date('d').'-access.log';
|
||
| 38 | } |
||
| 39 | |||
| 40 | if(!file_exists($logger)){
|
||
| 41 | echo 'No requests for a log tracker have been detected yet.'; |
||
| 42 | echo PHP_EOL; |
||
| 43 | exit(); |
||
| 44 | } |
||
| 45 | |||
| 46 | $tailCommand = 'tail -n 1 -f '.escapeshellarg($logger).''; |
||
| 47 | |||
| 48 | while (@ ob_end_flush()); // end all output buffers if any |
||
| 49 | |||
| 50 | $proc = popen($tailCommand, 'r'); |
||
| 51 | |||
| 52 | $number = 0; |
||
| 53 | while (!feof($proc)) |
||
| 54 | {
|
||
| 55 | $result = fread($proc, 4096); |
||
| 56 | if(preg_match('@\{(.*)\}@',$result,$output)){
|
||
| 57 | $outputArray = json_decode($output[0],1); |
||
| 58 | |||
| 59 | $outputArray['trackNumber'] = ++$number; |
||
| 60 | |||
| 61 | if(app()->has('track.log')){
|
||
| 62 | |||
| 63 | $track = app()->get('track.log');
|
||
| 64 | echo $track($outputArray,$this->argument); |
||
| 65 | } |
||
| 66 | } |
||
| 67 | @ flush(); |
||
| 68 | } |
||
| 71 | } |