시놀로지 로그 표시 잡음 필터 추가

This commit is contained in:
seo
2026-07-25 20:00:22 +09:00
parent 756464643c
commit 677fad56f7
2 changed files with 78 additions and 4 deletions
+77 -3
View File
@@ -121,9 +121,10 @@ function dmesg_log(): array
];
}
function text_log_tail(string $path, string $label, int $limit = 500): array
function text_log_tail(string $path, string $label, int $limit = 500, ?callable $lineFilter = null, int $displayLimit = 500): array
{
$limit = max(1, min(1000, $limit));
$limit = max(1, min(10000, $limit));
$displayLimit = max(1, min(1000, $displayLimit));
$stat = sh(['/usr/bin/stat', '-c', '%s|%Y', $path], true, 3);
if ((int)$stat['code'] !== 0) {
return [
@@ -157,20 +158,93 @@ function text_log_tail(string $path, string $label, int $limit = 500): array
preg_split('/\R/', trim((string)$tail['out'])) ?: [],
static fn($line): bool => trim((string)$line) !== ''
));
$rawLineCount = count($lines);
if ($lineFilter !== null) {
$lines = array_values(array_filter($lines, $lineFilter));
}
if (count($lines) > $displayLimit) {
$lines = array_slice($lines, -$displayLimit);
}
return [
'path' => $path,
'available' => true,
'lines' => array_reverse($lines),
'line_count' => count($lines),
'raw_line_count' => $rawLineCount,
'size_bytes' => $size,
'updated_at' => $mtime > 0 ? date('Y-m-d H:i:s', $mtime) : null,
];
}
function synology_remote_log_visible(string $line): bool
{
if (str_contains($line, 'Last message ') && str_contains($line, 'suppressed by syslog-ng')) {
return false;
}
if (preg_match('/\ssynotifyd\[\d+\]\s/', $line)) {
return false;
}
if (preg_match('/\ssynoelasticd\[\d+\]\s/', $line)) {
$noise = [
'(UpsertByID)',
'(SetByID)',
'(DelByID)',
'(DelByQuery)',
'(Commit) Commit: fileindex_',
];
foreach ($noise as $needle) {
if (str_contains($line, $needle)) {
return false;
}
}
}
if (preg_match('/\sfileindexd\[\d+\]\s/', $line)) {
$noise = [
'ProcessOP BEGIN: IndexUpsert',
'ProcessOP DONE!: IndexUpsert',
'ProcessOP SKIPPED: IndexUpsert',
'ProcessOP BEGIN: IndexReindex',
'ProcessOP DONE!: IndexReindex',
'ProcessOP SKIPPED: IndexReindex',
'(Process) Worker<',
'PrepareTmpOPtree',
'CheckClearOldTmpOPtree',
'BuildTree',
'Commit [fileindex_',
];
foreach ($noise as $needle) {
if (str_contains($line, $needle)) {
return false;
}
}
}
if (preg_match('/\sscemd\[\d+\]\s/', $line)) {
$noise = [
'Could not open file `/dev/i2c-1',
'Could not open file `/dev/i2c/1',
'Fail to initLedBrightnessConfig',
'No brightness setting',
'Fail to init config list',
'Fail to set led brightness.',
];
foreach ($noise as $needle) {
if (str_contains($line, $needle)) {
return false;
}
}
}
return true;
}
function synology_remote_log(): array
{
return text_log_tail('/var/log/remote/synology/chaegeon.log', 'synology remote');
return text_log_tail('/var/log/remote/synology/chaegeon.log', 'synology remote', 5000, 'synology_remote_log_visible');
}
function command_first_line(array $cmd, bool $root = false, int $timeout = 3): string