Welcome Guest, Not a member yet? Register   Sign In
Display error log

(This post was last modified: 10-07-2018, 12:42 AM by imabot.)

In the admin back office of my website, I would like to display logged errors (located in /application/logs). Is there a simple way to do that or should we parse the files with file_get_contents ?

file_get_contents() will work just fine. The log files are plain text so no "parsing" is needed. Simply take the string returned and pass it to your view.

You could also use fopen() and its associated filesystem functions to read the data. A more robust and reusable implementation might want to be able to read compressed files. My solution to that uses gzopen() instead of fopen() and looks like this.

PHP Code:
define('LINESP'"<br><br>");  //if you want
$logFile "";
$handle  gzopen($file"rb");  //$file is the full path to the file
   while( ! gzeof($handle))
       $buffer gzgets($handle4096);
       $logFile .= $buffer LINESP;
//pass file contents to view
$data['logFile'] = $logFile;

gzopen() also reads uncompressed files making it a multi-purpose solution.

(This post was last modified: 10-07-2018, 08:49 PM by imabot.)

Thank you, that's perfect. 

By the way, I made a parser for displaying formatted error messages. I assumed that one error = one line, but I realized that SQL queries made with the Query Builder Class contains carriage return. When an error contains a SQL query, it become impossible to differentiate this single multi-line message from several single-line messages. 

Of course, checking for DEBUG, INFO at the beginning of the line is possible, but not very satisfying if the query contains one of this keyword ?

That's not really important, but may be an improvement for CodeIgniter 4 !

Theme © iAndrew 2016 - Forum software by © MyBB