粘贴PHP错误日志内容(NGINX 下PHP网站错误日志)。
作用:提取PHP Warning/Notice:路径+错误行+报错信息+按出现次数排序。
以上已满足本人自己LNMP环境的调试需求,其他环境自己评估是否可用。
<?php
//整理与分享:yujianyue<15058593138@qq.com>
$ti = "错误日志提取分析辅助工具";
function tipx($logt){
preg_match_all('/PHP (Warning|Notice):(.*?) in \/wwwroot\/(.*?) on line ([0-9]+)/',$logt,$ma);
$errors = array_map(function($message, $file, $line) {return "$file\t=>$line\t=>$message";
}, $ma[2], $ma[3], $ma[4]);
$uni = array_count_values($errors);arsort($uni);
return $uni;
}if($_GET["x"] == "cha"){
$txts = isset($_POST['tips']) ? Trim($_POST['tips']) : '';
$lisa = tipx($txts);
echo "<h2><strong>以下信息仅供参考</strong></h2>\r\n";echo "<table>";echo "<tr class='tt'><td>路径</td><td>行</td><td>报错信息</td><td>次数</td></tr>\r\n";
foreach($lisa as $zz => $ges){$zz = str_replace("\t=>","</td><td>",$zz);echo "<tr><td>$zz</td><td>$ges</td></tr>\r\n";
}echo "</table>";
exit();
}
?>
<!DOCTYPE html>
<html>
<head>
<title><?php echo $ti;?></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0">
<meta name="apple-mobile-web-app-capable" content="yes" />
<script type="text/javascript">
console.log("问题反馈电话:","15058593138");
console.log("问题反馈邮件:","admin@12391.net");
function $(objId){
return document.getElementById(objId);
}
function loadcha(xid) {
var xmlhttp;
var Stxt= "nums=aa";
Stxt+="&tips="+ encodeURIComponent($("tips").value);
//$("tips").innerHTML = "正在加载...";
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var btxt = xmlhttp.response;
if(btxt == "err01"){ $("tipx").innerHTML = "!"; return false;}
$('tipx').innerHTML = xmlhttp.response;
}
}
xmlhttp.open("POST", "?x=cha&tt="+Math.random(), true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send(Stxt);
}</script>
<style>
div,#tipx{display:block;width:99.7%;border:0;margin-top:5px;}
textarea{display:block;width:99.7%;border:1px solid #ccc;height:160px;}
table{margin:20px auto;border-left:1px solid #a2c6d3;border-top:3px solid #0180CF;font-size:12px;width:99.7%;}
table td{border-right:1px solid #a2c6d3;border-bottom:1px solid #a2c6d3;padding:2px;word-wrap:break-word;word-break:break-all;}
td{min-width:30px;max-width:490px;}
.tt{background-color: #f2f2f2;}
b{color:red;}
#submit{ height:35px;}
</style>
</head>
<body><form class="form" id="form" method="POST" act="?act=cha" ><h3><?php echo $ti;?></h3>
粘贴单个相对本文件的路径;或者粘贴错误日志内容。<br>
作用:提取PHP Warning/Notice:路径+错误行+报错信息+按出现次数排序。<br>
以上已满足本人自己的调试需求,如需更多规则有能力者可自己调整。
<textarea id="tips">err.txt.log</textarea><input type="button" id="submit" value="提交" onclick="loadcha('xid')">
<div id="tipx"></div></form>
</body>
</html>