Feat: Add logging
This commit is contained in:
@@ -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