add logging
This commit is contained in:
@@ -39,9 +39,11 @@ class MeilisearchFilesCleanupCommand extends Command
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
// wichtig für Contao 4.13 & 5.x
|
||||
$this->framework->initialize();
|
||||
|
||||
$this->log('Cleaner gestartet');
|
||||
|
||||
try {
|
||||
$grace = max(0, (int) $input->getOption('grace'));
|
||||
$dryRun = (bool) $input->getOption('dry-run');
|
||||
$cutoff = time() - $grace;
|
||||
@@ -52,12 +54,16 @@ class MeilisearchFilesCleanupCommand extends Command
|
||||
->execute($cutoff)
|
||||
->cnt;
|
||||
|
||||
$output->writeln(sprintf(
|
||||
'<comment>[DRY-RUN]</comment> %d stale file(s) would be removed (last_seen < %s)',
|
||||
$message = sprintf(
|
||||
'[DRY-RUN] %d stale file(s) would be removed (last_seen < %s)',
|
||||
$count,
|
||||
date('Y-m-d H:i:s', $cutoff)
|
||||
));
|
||||
);
|
||||
|
||||
$output->writeln('<comment>' . $message . '</comment>');
|
||||
$this->log($message);
|
||||
|
||||
$this->log('Cleaner successfully stopped');
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
@@ -66,12 +72,35 @@ class MeilisearchFilesCleanupCommand extends Command
|
||||
->execute($cutoff)
|
||||
->affectedRows;
|
||||
|
||||
$output->writeln(sprintf(
|
||||
'<info>Removed %d stale file(s)</info> (last_seen < %s)',
|
||||
$message = sprintf(
|
||||
'Removed %d stale file(s) (last_seen < %s)',
|
||||
$affected,
|
||||
date('Y-m-d H:i:s', $cutoff)
|
||||
));
|
||||
);
|
||||
|
||||
$output->writeln('<info>' . $message . '</info>');
|
||||
$this->log($message);
|
||||
|
||||
$this->log('Cleaner successfully stopped');
|
||||
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
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -24,12 +24,34 @@ class MeilisearchIndexCommand extends Command
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$this->log('Meilisearch index gestartet');
|
||||
$output->writeln('<info>Meilisearch index started</info>');
|
||||
|
||||
try {
|
||||
$this->indexService->run();
|
||||
|
||||
$this->log('Meilisearch index successfully stopped');
|
||||
$output->writeln('<info>Meilisearch index finished</info>');
|
||||
|
||||
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
|
||||
));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user