Skip to content

Commit

Permalink
Update Errorlogger to 1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
instantflorian committed Jul 23, 2020
1 parent 7b77457 commit 8e06436
Show file tree
Hide file tree
Showing 3 changed files with 241 additions and 63 deletions.
110 changes: 96 additions & 14 deletions wbce/modules/errorlogger/backend.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,6 @@ div.logline.even {
background: #f3f3f3;
}

.lvlink a {
color: #ff0000;
text-decoration: none;
background: #fff;
padding: 3px 10px;
}

.lvlink {
float: right;
font-size: 14px;
margin-right: 2px;
margin-left: 10px;
}

.newline {
background: #fff7e1 !important;
}
Expand Down Expand Up @@ -84,4 +70,100 @@ div.logline.even {
color: #fff;
padding: 10px;
margin-bottom: 10px;
}

/**
* Table view, added by Stefanek
*/

.table-errlog {
border: 2px solid white;
width: 100%;
min-width: 700px;
font-size:12px;
}
.table-errlog tr.odd td{
background-color: #f7f7f7!important;
}
.table-errlog td, .table-errlog th{
vertical-align: top;
padding:3px;
border: 1px solid lightgrey;
border-bottom: 2px solid lightgray;
}.table-errlog th{
text-align: center;
}
.table-errlog td:nth-of-type(3){
text-align: right;
white-space: nowrap;
}
.table-errlog td:nth-of-type(1){
text-align: center;
width: 60px;
}
.table-errlog tr.color-red td{
background-color: #f7eaea!important;
}
span.file{
font-family: courier;
font-size: 12.5px;
color: #0c33de;
}

div.tool-header{
display:block;
background:#f7f7f7;
padding: 3px;
}
div.tool-header h2{
float:left;
}

.tool-header:after{
content: "";
display: table;
clear: both;
}
ul.header-links{
padding:6px;
list-style-type: none;
display: inline;
float:right;
}
ul.header-links li {
display: inline;
font-size: 14px;
margin: 3px 2px;
line-height: 140%;
}
ul.header-links li a {
text-decoration: none;
background: #fff;
padding: 3px 7px;
}
li.reload-link{
color: #ff0000;
}
li.delete-link a{
color: #ff0000;
}
ul.header-links li.viewlink{
font-weight: bold;
font-size: 12px;
margin-left: 0px;
}
ul.header-links li.viewlink a{
padding: 3px 4px;
border-radius: 5px;
border: 1px solid lightgray;
color: grey;
}

ul.header-links li.active a, ul.header-links li.viewlink a:hover{
-webkit-box-shadow: inset 1px 1px 4px 0px rgba(0,0,0,0.2);
-moz-box-shadow: inset 1px 1px 4px 0px rgba(0,0,0,0.2);
box-shadow: inset 1px 1px 4px 0px rgba(0,0,0,0.2);
}
ul.header-links li.active a{
background-color: #f2ffd6;
}
27 changes: 18 additions & 9 deletions wbce/modules/errorlogger/info.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
// Must include code to stop this file being access directly
if(defined('WB_PATH') == false) { die("Cannot access this file directly"); }

$module_directory = 'errorlogger';
$module_name = ' Errorlog viewer';
$module_function = 'tool,preinit,initialize';
$module_version = '1.0.0';
$module_platform = '1.4.x';
$module_author = 'Ruud Eisinga - Dev4me';
$module_license = 'GNU General Public License';
$module_directory = 'errorlogger';
$module_name = 'Errorlog viewer';
$module_function = 'tool,preinit,initialize';
$module_version = '1.1.0';
$module_platform = '1.4.x';
$module_author = 'Ruud Eisinga - Dev4me';
$module_license = 'GNU General Public License';
$module_description = 'Catch PHP warnings and errors into a logfile and view them using this tool.';
$module_icon = 'fa fa-tasks';
//$module_level = 'core';
$module_icon = 'fa fa-tasks';
//$module_level = 'core';


/*
Expand All @@ -34,5 +34,14 @@
*
*/

/*******************************************************************************
DEVELOPMENT HISTORY (Change Log):
v.1.1.0 2020-07-23 Christian M. Stefan (Stefanek)
[+] Implementation of Table View
[c] changes to CSS file adding styles for the Table View
*/



167 changes: 127 additions & 40 deletions wbce/modules/errorlogger/tool.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,25 @@
$cookie = 'errorlog_colors';
$color_set = false;
if(isset($_GET['color'])) {
if($_GET['color']=='1') {
setcookie($cookie, '1', time() + (86400 * 365));
$_COOKIE[$cookie] = '1';
} else {
setcookie($cookie, null, 1);
unset($_COOKIE[$cookie]);
}
if($_GET['color']=='1') {
setcookie($cookie, '1', time() + (86400 * 365));
$_COOKIE[$cookie] = '1';
} elseif($_GET['color']=='2') {
setcookie($cookie, '2', time() + (86400 * 365));
$_COOKIE[$cookie] = '2';
} else {
setcookie($cookie, null, 1);
unset($_COOKIE[$cookie]);
}
}
$colorclass = '';
$use_color = $link.'&color=1';
$use_color_text = 'Use Colors';

$view = 0;
$colorclass = "";
if(isset($_COOKIE[$cookie])) {
$colorclass = ' color';
$use_color = $link.'&color=0';
$use_color_text = 'No Colors';
$view = $_COOKIE[$cookie];
$colorclass = " color";
}


$res = array("Great news. No errors reported");

$lines = 250;
Expand All @@ -53,49 +54,135 @@
if(!$logfile) $logfile = WB_PATH.'/var/logs/php_error.log.php';

if(isset($_GET['delete'])) {
if(file_exists($logfile)) {
$now = date("Ymd_Hi");
rename ( $logfile , dirname($logfile).'/'.$now.'_php_error.log.php' );
$lname = str_replace(WB_PATH,'',dirname($logfile).'/'.$now.'_php_error.log.php');
$warning .= '<div class="messagelevel">Message: Logfile renamed to '.$lname.'</div>';
}
if(file_exists($logfile)) {
$now = date("Ymd_Hi");
rename ( $logfile , dirname($logfile).'/'.$now.'_php_error.log.php' );
$lname = str_replace(WB_PATH,'',dirname($logfile).'/'.$now.'_php_error.log.php');
$warning .= '<div class="messagelevel">Message: Logfile renamed to '.$lname.'</div>';
}
}

if(!isset($_SESSION['lastview'])) $_SESSION['lastview'] = date('c');

if(file_exists($logfile)) {
$res = file($logfile);
unset($res[0]); // = strip_tags($res[0]);
$res = array_slice($res, -$lines);
$res = file($logfile);
unset($res[0]); // = strip_tags($res[0]);
$res = array_slice($res, -$lines);
}
if(count($res) == 0) $res = array("Great news. No errors reported");
$row = "even";
$last = strtotime($_SESSION['lastview']);

$tmpErrorLevel = error_reporting(-1);
$warning .= $tmpErrorLevel != E_ALL ? '<div class="errorlevel">Note: Do not forget to set your error reporting to the maximum level! Currently this is not the case.</div>':'';


?>
<h2 style="display:block;background:#f7f7f7;padding:10px;">Errorlog viewer <span class="lvlink"><a href="<?php echo $use_color ?>"><?php echo $use_color_text ?></a></span> <span class="lvlink"><a href="<?php echo $del ?>">Delete logfile</a></span> <span class="lvlink"><a href="<?php echo $link ?>">Reload</a></span></h2>
<?php echo $warning ?>
<div class="logviewWrapper<?php echo $colorclass ?>">
<?php foreach($res as $line) {
$row = $row == "odd" ? "even" : "odd";
$curline = strtotime(str_replace(array('[',']'),'',substr($line,0,26)));
$row = $curline > $last ? " newline": $row;
$type = '';
if(strpos($line,"Notice]")!== false) $type = " lognotice";
if(strpos($line,"Warning]")!== false) $type = " logwarning";
if(strpos($line,"Error]")!== false) $type = " logerror";
if(strpos($line,"PHP Parse error")!== false) $type = " logerror";
if(strpos($line,"Exception]")!== false) $type = " logerror";
if(strpos($line,"Deprecated]")!== false) $type = " logdeprecated";
echo '<div class="logline '.$row.$type.'">'.$line.'</div>';

<div class="tool-header">
<h2>Errorlog viewer</h2>
<ul class="header-links">
<li class="reload-link"><a href="<?=$link ?>"><i class="fa fa-refresh"></i> Reload</a></li>
<li class="delete-link"><a href="<?=$del ?>"><i class="fa fa-trash"></i> Delete logfile</a></li>
<li class="viewlink<?=$view == '0' ? ' active':''?>"><a href="<?=$link.'&color=0'?>">Plain View</a></li>
<li class="viewlink<?=$view == '1' ? ' active':''?>"><a href="<?=$link.'&color=1'?>">Color View</a></li>
<li class="viewlink<?=$view == '2' ? ' active':''?>"><a href="<?=$link.'&color=2'?>">Table View</a></li>
</ul>
</div>
<?=$warning ?>
<div class="logviewWrapper<?=$colorclass ?>">
<?php
if($view == '0' or $view == '1'){
foreach($res as $line) {
$row = $row == "odd" ? "even" : "odd";
$curline = strtotime(str_replace(array('[',']'),'',substr($line,0,26)));
$row = $curline > $last ? " newline": $row;
$type = '';
if(strpos($line,"Notice]")!== false) $type = " lognotice";
if(strpos($line,"Warning]")!== false) $type = " logwarning";
if(strpos($line,"Error]")!== false) $type = " logerror";
if(strpos($line,"PHP Parse error")!== false) $type = " logerror";
if(strpos($line,"Exception]")!== false) $type = " logerror";
if(strpos($line,"Deprecated]")!== false) $type = " logdeprecated";
echo '<div class="logline '.$row.$type.'">'.$line.'</div>';
}
} else {
$aLines = log_to_array($res);
if(count($aLines) > 1){
?>
<table class="table-errlog">
<tr>
<th><?=$TEXT['DATE'].'/',$TEXT['TIME']?></th>
<th>Type</th>
<th>Source</th>
<th>Message</th>
</tr>
<?php foreach($aLines as $rec){
$row = $row == "odd" ? "even" : "odd";
?>
<tr class="<?=$row?> color-<?=$rec['color']?>">
<td>
<?=$rec['date']?> <b><?=$rec['time']?></b>
</td>
<td style="font-weight:bold;color: <?=$rec['color']?>;text-align: center;">
<?=$rec['type']?>
</td>
<?php if($rec['type'] == 'Exception'): ?>
<td colspan="2" style="text-align:left; color: red;">
<?=$rec['primary']?>
</td>
<?php else: ?>
<td>
<span class="file"><?=$rec['primary']?></span> <?php if($rec['type'] != 'Exception'): ?>
<b>L:<?=$rec['p_line']?></b>
<?php endif; ?><br>
<?php if($rec['type'] != 'Exception'): ?>
<i>from</i> <span class="file"><?=$rec['secondary']?></span> <b>L:<?=$rec['s_line']?></b>
<?php endif; ?>
</td>
<td>
<?=$rec['msg']?>
</td>
<?php endif; ?>
</tr>
<?php } ?>
</table>
<?php
} else {
echo 'Great news. No errors reported';
}
}
?>
</div>
<?php
function log_to_array($aLines){
$aRetVal = [];
foreach($aLines as $line){
$arr = explode('[', $line);
$arr2 = [];
foreach($arr as $parts){
$arr2[] = explode(']', $parts);
}
$aDateTime = explode('T',$arr2[0][0]);
$sType = @$arr2[1][0];
$sColor = 'inherit';
if($sType == 'Exception')
$sColor = 'red';
if($sType == 'Warning')
$sColor = 'red';
$aRetVal[] = array(
'color' => $sColor,
'date' => @$aDateTime[0],
'time' => trim(str_replace('+00:00', '', @$aDateTime[1])),
'type' => $sType,
'primary' => str_replace(':', '', @$arr2[1][1]),
'p_line' => @$arr2[2][0],
'secondary' => trim(str_replace(['from', ':'], '', @$arr2[2][1])),
's_line' => @$arr2[3][0],
'msg' => trim(@$arr2[3][1]),
);

}
return $aRetVal;
}
$_SESSION['lastview'] = date('c');


Expand Down

0 comments on commit 8e06436

Please sign in to comment.