Plugin Directory

Changeset 2293017


Ignore:
Timestamp:
04/27/2020 08:41:32 PM (6 years ago)
Author:
RNAGS
Message:

Reversed log read

File:
1 edited

Legend:

Unmodified
Added
Removed
  • reuters-direct/trunk/includes/log-widget.php

    r1834660 r2293017  
    4646        $log = __DIR__.'/logs/log_'.date('Y-m-d').'.txt';
    4747        $color = ['info'=>'#444444', 'notice'=>'#0074A2', 'error'=>'#DC0A0A'];
    48         echo '<div style="height:500px; overflow:auto;"><table style="display:block;">';
     48        $log_rows = [];
    4949        $handle = @fopen($log, "r");
    50         if ($handle) {
    51             while (($buffer = fgets($handle, 4096)) !== false) {
    52                 $log_split = str_replace('[','',explode('] ', $buffer));
    53                 echo '<tr style="font-size:12px;"><td style="min-width:150px; color:#777; vertical-align:top;">'.$log_split[0].'</td><td style="color:'.$color[$log_split[1]].';">'.$log_split[2].'</td></tr>';
     50        if($handle) {
     51            while(($buffer = fgets($handle, 4096)) !== false) {
     52                $log_rows[] = $buffer;
    5453            }
    55             if (!feof($handle)) {
     54            if(!feof($handle)) {
    5655                echo "Error: unexpected fgets() fail";
    5756            }
    5857            fclose($handle);
    5958        }
     59        $log_rows_rev = array_reverse($log_rows);
     60        echo '<div style="height:500px; overflow:auto;"><table style="display:block;">';
     61        foreach($log_rows_rev as $row) {
     62            $log_split = str_replace('[','',explode('] ', $row));
     63            echo '<tr style="font-size:12px;"><td style="min-width:150px; color:#777; vertical-align:top;">'.$log_split[0].'</td><td style="color:'.$color[$log_split[1]].';">'.$log_split[2].'</td></tr>';
     64        }
    6065        echo '</table></div>';
    6166    }
Note: See TracChangeset for help on using the changeset viewer.