Add detailed level of drill down into logs

This commit is contained in:
Brian Read 2024-07-15 16:15:39 +01:00
parent 54ceac1ee8
commit 3c1dc868aa
2 changed files with 36 additions and 1 deletions

View File

@ -0,0 +1,29 @@
<?php
header('Content-Type: text/plain');
$input_param = isset($_GET['id']) ? $_GET['id'] : '9999';
// Set the directory and file names
$directory = "/opt/mailstats/logs";
$files = ['current1', 'current2'];
function process_file($file_path, $input_param) {
$file = fopen($file_path, 'r');
$match = "/ $input_param /";
$endmatch = "/cleaning up after $input_param/";
while (($line = fgets($file)) !== false) {
// Check if the line contains the input_parameter
if (preg_match($match,$line) === 1) {
echo $line;
} elseif (preg_match($endmatch,$line) === 1) {
echo $line;
exit();
}
}
fclose($file);
}
chdir($directory);
foreach ($files as $file) {
process_file($file, $input_param);
}
?>

View File

@ -75,6 +75,7 @@ function generateLogDataTable($logData) {
$values = array_values($mergedData); $values = array_values($mergedData);
$output = '<table class="stripes" style="border-collapse: collapse; width:95%;overflow-x:auto; margin: 0.6% auto 0.6% auto;"><tbody>'; $output = '<table class="stripes" style="border-collapse: collapse; width:95%;overflow-x:auto; margin: 0.6% auto 0.6% auto;"><tbody>';
#$output = '<table class="stripes" style="border-collapse: collapse; width:95%;overflow-x:auto; margin:2%"><tbody>';
// Divide keys and values into sets of 6 // Divide keys and values into sets of 6
$chunks = array_chunk($keys, 6); $chunks = array_chunk($keys, 6);
@ -90,7 +91,12 @@ function generateLogDataTable($logData) {
} }
$output .= '</tr><tr>'; $output .= '</tr><tr>';
foreach ($chunk as $i => $key) { foreach ($chunk as $i => $key) {
$output .= '<td>' . htmlspecialchars($values[$chunkIndex * 6+ $i]) . '</td>'; $val = htmlspecialchars($values[$chunkIndex * 6+ $i]);
if ($key == 'id'){
$output .= '<td>' . "<a href='./ShowDetailedLogs.php?id=".$val."'</a>".$val."</td>";
} else {
$output .= '<td>' . $val . '</td>';
}
} }
$output .= '</tr>'; $output .= '</tr>';
} }