add logging

This commit is contained in:
Jürgen Mummert
2026-01-09 10:17:57 +01:00
parent 6329c9e790
commit b4cd9199c8
2 changed files with 77 additions and 26 deletions
+36 -7
View File
@@ -39,9 +39,11 @@ class MeilisearchFilesCleanupCommand extends Command
protected function execute(InputInterface $input, OutputInterface $output): int protected function execute(InputInterface $input, OutputInterface $output): int
{ {
// wichtig für Contao 4.13 & 5.x
$this->framework->initialize(); $this->framework->initialize();
$this->log('Cleaner gestartet');
try {
$grace = max(0, (int) $input->getOption('grace')); $grace = max(0, (int) $input->getOption('grace'));
$dryRun = (bool) $input->getOption('dry-run'); $dryRun = (bool) $input->getOption('dry-run');
$cutoff = time() - $grace; $cutoff = time() - $grace;
@@ -52,12 +54,16 @@ class MeilisearchFilesCleanupCommand extends Command
->execute($cutoff) ->execute($cutoff)
->cnt; ->cnt;
$output->writeln(sprintf( $message = sprintf(
'<comment>[DRY-RUN]</comment> %d stale file(s) would be removed (last_seen < %s)', '[DRY-RUN] %d stale file(s) would be removed (last_seen < %s)',
$count, $count,
date('Y-m-d H:i:s', $cutoff) date('Y-m-d H:i:s', $cutoff)
)); );
$output->writeln('<comment>' . $message . '</comment>');
$this->log($message);
$this->log('Cleaner successfully stopped');
return Command::SUCCESS; return Command::SUCCESS;
} }
@@ -66,12 +72,35 @@ class MeilisearchFilesCleanupCommand extends Command
->execute($cutoff) ->execute($cutoff)
->affectedRows; ->affectedRows;
$output->writeln(sprintf( $message = sprintf(
'<info>Removed %d stale file(s)</info> (last_seen < %s)', 'Removed %d stale file(s) (last_seen < %s)',
$affected, $affected,
date('Y-m-d H:i:s', $cutoff) date('Y-m-d H:i:s', $cutoff)
)); );
$output->writeln('<info>' . $message . '</info>');
$this->log($message);
$this->log('Cleaner successfully stopped');
return Command::SUCCESS; return Command::SUCCESS;
} catch (\Throwable $e) {
$this->log('Cleaner ERROR: ' . $e->getMessage());
$output->writeln('<error>' . $e->getMessage() . '</error>');
return Command::FAILURE;
}
}
/**
* Einheitliches Logging mit Zeitstempel
*/
private function log(string $message): void
{
error_log(sprintf(
'[%s] %s',
date('Y-m-d H:i:s'),
$message
));
} }
} }
+22
View File
@@ -24,12 +24,34 @@ class MeilisearchIndexCommand extends Command
protected function execute(InputInterface $input, OutputInterface $output): int protected function execute(InputInterface $input, OutputInterface $output): int
{ {
$this->log('Meilisearch index gestartet');
$output->writeln('<info>Meilisearch index started</info>'); $output->writeln('<info>Meilisearch index started</info>');
try {
$this->indexService->run(); $this->indexService->run();
$this->log('Meilisearch index successfully stopped');
$output->writeln('<info>Meilisearch index finished</info>'); $output->writeln('<info>Meilisearch index finished</info>');
return Command::SUCCESS; return Command::SUCCESS;
} catch (\Throwable $e) {
$this->log('Meilisearch index ERROR: ' . $e->getMessage());
$output->writeln('<error>' . $e->getMessage() . '</error>');
return Command::FAILURE;
}
}
/**
* Einheitliches Logging mit Zeitstempel
*/
private function log(string $message): void
{
error_log(sprintf(
'[%s] %s',
date('Y-m-d H:i:s'),
$message
));
} }
} }