Add Status column (Success/Warning/Error) to WHM logs list
Scans each log file for [ERROR] and [WARN] markers and displays a color-coded badge in the logs table. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -56,11 +56,13 @@ sub show_list {
|
||||
my $path = "$log_dir/$entry";
|
||||
next unless -f $path;
|
||||
my @stat = stat($path);
|
||||
my $status = _detect_log_status($path);
|
||||
push @files, {
|
||||
name => $entry,
|
||||
size => $stat[7] // 0,
|
||||
mtime => $stat[9] // 0,
|
||||
type => ($entry =~ /^cron-/) ? 'Cron' : 'Backup',
|
||||
name => $entry,
|
||||
size => $stat[7] // 0,
|
||||
mtime => $stat[9] // 0,
|
||||
type => ($entry =~ /^cron-/) ? 'Cron' : 'Backup',
|
||||
status => $status,
|
||||
};
|
||||
}
|
||||
closedir $dh;
|
||||
@@ -89,7 +91,7 @@ sub show_list {
|
||||
|
||||
print qq{<div class="overflow-x-auto rounded-box border border-base-content/5 bg-base-100">\n};
|
||||
print qq{<table class="table">\n};
|
||||
print qq{<thead><tr><th>Filename</th><th>Type</th><th>Date</th><th>Size</th><th></th></tr></thead>\n};
|
||||
print qq{<thead><tr><th>Filename</th><th>Type</th><th>Status</th><th>Date</th><th>Size</th><th></th></tr></thead>\n};
|
||||
print qq{<tbody>\n};
|
||||
|
||||
for my $f (@page_files) {
|
||||
@@ -102,6 +104,10 @@ sub show_list {
|
||||
print qq{<tr>\n};
|
||||
print qq{ <td><code>$esc_name</code></td>\n};
|
||||
print qq{ <td><span class="badge $badge badge-sm">$f->{type}</span></td>\n};
|
||||
my $status_badge = $f->{status} eq 'Error' ? 'badge-error'
|
||||
: $f->{status} eq 'Warning' ? 'badge-warning'
|
||||
: 'badge-success';
|
||||
print qq{ <td><span class="badge $status_badge badge-sm">$f->{status}</span></td>\n};
|
||||
print qq{ <td>$date</td>\n};
|
||||
print qq{ <td>$size</td>\n};
|
||||
print qq{ <td><button type="button" class="btn btn-secondary btn-sm" onclick="location.href='$href'">View</button></td>\n};
|
||||
@@ -315,6 +321,23 @@ sub _valid_log_filename {
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub _detect_log_status {
|
||||
my ($path) = @_;
|
||||
return 'Success' unless -f $path;
|
||||
my $has_warn = 0;
|
||||
if (open my $fh, '<', $path) {
|
||||
while (my $line = <$fh>) {
|
||||
if ($line =~ /\[ERROR\]/) {
|
||||
close $fh;
|
||||
return 'Error';
|
||||
}
|
||||
$has_warn = 1 if !$has_warn && $line =~ /\[WARN\]/;
|
||||
}
|
||||
close $fh;
|
||||
}
|
||||
return $has_warn ? 'Warning' : 'Success';
|
||||
}
|
||||
|
||||
sub _uri_escape {
|
||||
my $str = shift // '';
|
||||
$str =~ s/([^A-Za-z0-9\-._~])/sprintf("%%%02X", ord($1))/ge;
|
||||
|
||||
Reference in New Issue
Block a user