How to view PHP or Apache error log online in a browser?

40,307

Solution 1

See What commercial and open source competitors are there to Splunk? and I would recommend https://github.com/tobi/clarity

Simple and easy tool.

Solution 2

A simple php code to read log and print:

<?php

  exec('tail /var/log/apache2/error.log', $error_logs);

  foreach($error_logs as $error_log) {

       echo "<br />".$error_log;
  }

 ?>

You can embed error_log php variable in html as per your requirement. The best part is tail command will load the latest errors which wont make too load on your server.

You can change tail to give output as you want

Ex. tail myfile.txt -n 100 // it will give last 100 lines

Solution 3

Since everyone is suggesting clarity, I would also like to mention tailon. I wrote tailon as a more modern and secure alternative to clarity. It's still in its early stages of development, but the functionality you need is there. You may also use wtee, if you're only interested in following a single log file.

Solution 4

You good make a script that reads the error logs from apache2..

$apache_errorlog = file_get_contents('/var/log/apache2/error.log');

if its not working.. trying to get it with the php functions exec or shell_exec and the command 'cat /var/log/apache2/error.log'

EDIT: If you have multi servers(i quess with webservers on it) you can create a file on the machine, when you make a request to that script(hashed connection) you get the logs from that server

Solution 5

I've found this solution https://code.google.com/p/php-tail/

It's working perfectly. I only needed to change the filesize, because I was getting an error first.

56       if($maxLength > $this->maxSizeToLoad) {
57                $maxLength = $this->maxSizeToLoad;
58                // return json_encode(array("size" => $fsize, "data" =>   array("ERROR: PHPTail attempted to load more (".round(($maxLength / 1048576), 2)."MB) then the maximum size (".round(($this->maxSizeToLoad / 1048576), 2)    ."MB) of bytes into memory. You should lower the defaultUpdateTime to prevent this from happening. ")));
59       }

And I've added default size, but it's not needed

125       lastSize = <?php echo filesize($this->log) || 1000; ?>;
Share:
40,307
eric
Author by

eric

Updated on June 02, 2020

Comments

  • eric
    eric almost 4 years

    Is there a way to view the PHP error logs or Apache error logs in a web browser?

    I find it inconvenient to ssh into multiple servers and run a "tail" command to follow the error logs. Is there some tool (preferably open source) that shows me the error logs online (streaming or non-streaming?

    Thanks

  • padawanTony
    padawanTony over 7 years
    Isn't this going to create a warning such as PHP Warning: file_get_contents(/var/log/apache2/error.log): failed to open stream: Permission denied? Of course given that a basic security system is set up.