Feat: Add logging
This commit is contained in:
@@ -5,6 +5,7 @@ namespace App\Command;
|
||||
use App\BusProNet\DataProvider\HotelDataProvider;
|
||||
use App\BusProNet\DataProvider\PickupDataProvider;
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
@@ -22,6 +23,7 @@ class BpnImportCommand extends Command
|
||||
private readonly Connection $connection,
|
||||
private readonly HotelDataProvider $hotelDataProvider,
|
||||
private readonly PickupDataProvider $pickupDataProvider,
|
||||
private readonly LoggerInterface $logger,
|
||||
private readonly string $xmlFilesPath
|
||||
) {
|
||||
parent::__construct();
|
||||
@@ -124,7 +126,9 @@ class BpnImportCommand extends Command
|
||||
}
|
||||
}
|
||||
|
||||
$io->info('Added '.$addedCount.' and updated '.$updatedCount.' destinations');
|
||||
$logMessage = 'Added '.$addedCount.' and updated '.$updatedCount.' destinations';
|
||||
$io->info($logMessage);
|
||||
$this->logger->info($logMessage);
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Logging;
|
||||
|
||||
use Monolog\LogRecord;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
|
||||
class InjectUserProcessor
|
||||
{
|
||||
public function __construct(private readonly Security $security)
|
||||
{}
|
||||
|
||||
public function __invoke(LogRecord $record): LogRecord
|
||||
{
|
||||
if (isset($record->extra['user'])) {
|
||||
return $record;
|
||||
}
|
||||
|
||||
if ('cli' === php_sapi_name()) {
|
||||
$record->extra['user'] = [
|
||||
'id' => null,
|
||||
'username' => 'system',
|
||||
'role' => 'system',
|
||||
];
|
||||
return $record;
|
||||
} elseif (null === $user = $this->security->getUser()) {
|
||||
return $record;
|
||||
}
|
||||
|
||||
$record['extra']['user'] = [
|
||||
'id' => $user->getId(),
|
||||
'email' => $user->getEmail(),
|
||||
'roles' => $user->getRoles(),
|
||||
];
|
||||
|
||||
return $record;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user