-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogs-helper.php
77 lines (62 loc) · 2.44 KB
/
logs-helper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/*
* Project: Update API
* Author: Vontainment
* URL: https://vontainment.com
* File: logs-helper.php
* Description: WordPress Update API
*/
function processLogFile($logFile)
{
$log_file_path = LOG_DIR . "/$logFile"; // path to the log file
$output = ''; // Variable to store the output
if (file_exists($log_file_path)) {
// read the log file into an array
$log_array = file($log_file_path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
// group the log entries by domain name
$log_by_domain = [];
foreach ($log_array as $entry) {
list($domain, $date, $status) = explode(' ', $entry);
$log_by_domain[$domain] = ['date' => $date, 'status' => $status];
}
// Start the output buffering
ob_start();
echo '<div class="log-row">';
foreach ($log_by_domain as $domain => $entry) {
// Calculate the difference in days from the log entry date to now
$date_diff = (strtotime(date('Y-m-d')) - strtotime($entry['date'])) / (60 * 60 * 24);
$classes = '';
// Add classes based on the status and date difference
if ($entry['status'] == 'Failed') {
$classes .= ' error';
} elseif ($entry['status'] == 'Success') {
$classes .= ' success';
}
if ($date_diff > 30) {
$classes .= ' lost';
}
// Trim any extra spaces from the classes string
$classes = trim($classes);
// display the entry for each domain
echo '<div class="log-sub-box' . ($classes ? " $classes" : '') . '">';
echo '<h3>' . $domain . '</h3>';
if ($entry['status'] == 'Failed') {
echo '<p class="log-entry" style="color:red;">' . $entry['date'] . ' ' . $entry['status'] . '</p>';
} else {
echo '<p class="log-entry" style="color:green;">' . $entry['date'] . ' ' . $entry['status'] . '</p>';
}
echo '</div>';
}
echo '</div>';
// store the buffered output into the $output variable
$output = ob_get_contents();
// end output buffering
ob_end_clean();
// Now, $output variable contains the output
return $output;
} else {
return 'Log file not found.';
}
}
$ploutput = processLogFile('plugin.log');
$thoutput = processLogFile('theme.log');