Linux 如何在浏览器中在线查看 PHP 或 Apache 错误日志?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7947125/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to view PHP or Apache error log online in a browser?
提问by eric
Is there a way to view the PHP error logs or Apache error logs in a web browser?
有没有办法在 Web 浏览器中查看 PHP 错误日志或 Apache 错误日志?
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?
我发现通过 ssh 连接到多个服务器并运行“tail”命令来跟踪错误日志很不方便。是否有一些工具(最好是开源的)可以在线显示错误日志(流媒体或非流媒体)?
Thanks
谢谢
采纳答案by Petr
See What commercial and open source competitors are there to Splunk?and I would recommend https://github.com/tobi/clarity
请参阅Splunk 有哪些商业和开源竞争对手?我会推荐https://github.com/tobi/clarity
Simple and easy tool.
简单易用的工具。
回答by Yoram de Langen
You good make a script that reads the error logs from apache2..
您最好制作一个脚本,从 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'
如果它不工作..试图用php函数exec
或shell_exec
命令'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
编辑:如果你有多个服务器(我问它上面有网络服务器)你可以在机器上创建一个文件,当你向那个脚本(散列连接)发出请求时,你从那个服务器获取日志
回答by gvalkov
Since everyone is suggesting clarity, I would also like to mention tailon. I wrote tailonas 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.
既然大家都在暗示清晰,我也想提一下tailon。我写tailon作为一种更现代、更安全的替代清晰度。它仍处于开发的早期阶段,但您需要的功能已经存在。如果您只对跟踪单个日志文件感兴趣,您也可以使用wtee。
回答by Richard
I've found this solution https://code.google.com/p/php-tail/
我找到了这个解决方案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; ?>;
回答by ToX 82
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.
我知道这个问题有点老了,但是(连同缺乏好的选择)它让我有了创建这个小型(开源)网络应用程序的想法。https://github.com/ToX82/logHappens。它可以在线使用,但我会使用 .htpasswd 作为基本登录系统。我希望它有帮助。
回答by B.S.B.
A simple php code to read log and print:
一个简单的php代码来读取日志和打印:
<?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.
您可以根据需要在 html 中嵌入 error_log php 变量。最好的部分是tail
命令将加载最新的错误,而不会在您的服务器上加载太多。
You can change tail
to give output as you want
您可以根据tail
需要更改以提供输出
Ex. tail myfile.txt -n 100
// it will give last 100 lines
前任。tail myfile.txt -n 100
// 它将给出最后 100 行
回答by Keaser
I recommend LogHappens: https://loghappens.com, it allows you to view the error log in web, and this is what it looks like:
我推荐 LogHappens: https://loghappens.com,它允许你在 web 中查看错误日志,它是这样的:
LogHappens supports kinds of web server log format, it comes with parses for Apache and CakePHP, and you can write your own.
LogHappens 支持多种 Web 服务器日志格式,它带有针对 Apache 和 CakePHP 的解析,您可以编写自己的。
You can find it here: https://github.com/qijianjun/logHappens
你可以在这里找到它: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)
- 支持token安全,没有config.php中的token就不能访问站点
- 支持 IP 白名单以确保安全和隐私
- 支持配置ajax请求间隔
- 支持从本地加载静态文件(用于本地开发环境)