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

7

13

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

Stomachache answered 30/10, 2011 at 19:11 Comment(0)
C
9

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

Simple and easy tool.

Carrasco answered 30/10, 2011 at 19:30 Comment(0)
M
11

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

Massorete answered 11/8, 2017 at 13:8 Comment(0)
C
9

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

Simple and easy tool.

Carrasco answered 30/10, 2011 at 19:30 Comment(0)
I
9

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.

Iranian answered 5/6, 2013 at 9:39 Comment(0)
P
6

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

Pearlene answered 30/10, 2011 at 19:16 Comment(1)
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.Allonge
G
2

I recommend LogHappens: https://loghappens.com, it allows you to view the error log in web, and this is what it looks like:

LogHappens supports kinds of web server log format, it comes with parses for Apache and CakePHP, and you can write your own.

You can find it here: https://github.com/qijianjun/logHappens

It's open source and free, I forked it and do some work to make it work better in dev env or in public env. That is:

  • Support token for security, one can't access the site without the token in config.php
  • Support IP whitelists for security and privacy
  • Sopport config the interval between ajax requests
  • Support load static files from local (for local dev env)
Giacobo answered 2/6, 2019 at 3:24 Comment(0)
F
1

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; ?>;
Fayefayette answered 12/6, 2013 at 8:17 Comment(0)
S
1

I know this question is a bit old, but (along with the lack of good choices) it gave me the idea to create this tiny (open source) web app. https://github.com/ToX82/logHappens. It can be used online, but I'd use an .htpasswd as a basic login system. I hope it helps.

Soloist answered 7/4, 2017 at 13:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.