Log the name of the CLI user, when actions were done from the CLI.

This commit is contained in:
Jan Böhmer 2023-04-07 22:44:59 +02:00
parent c91a6640ff
commit 6443d8e2bf
6 changed files with 124 additions and 2 deletions

View file

@ -24,6 +24,7 @@ namespace App\Services\LogSystem;
use App\Entity\LogSystem\AbstractLogEntry;
use App\Entity\UserSystem\User;
use App\Services\Misc\ConsoleInfoHelper;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Security\Core\Security;
@ -34,14 +35,17 @@ class EventLogger
protected array $whitelist;
protected EntityManagerInterface $em;
protected Security $security;
protected ConsoleInfoHelper $console_info_helper;
public function __construct(int $minimum_log_level, array $blacklist, array $whitelist, EntityManagerInterface $em, Security $security)
public function __construct(int $minimum_log_level, array $blacklist, array $whitelist, EntityManagerInterface $em,
Security $security, ConsoleInfoHelper $console_info_helper)
{
$this->minimum_log_level = $minimum_log_level;
$this->blacklist = $blacklist;
$this->whitelist = $whitelist;
$this->em = $em;
$this->security = $security;
$this->console_info_helper = $console_info_helper;
}
/**
@ -67,6 +71,11 @@ class EventLogger
$logEntry->setUser($user);
}
//Set the console user info, if the log entry was created in a console command
if ($this->console_info_helper->isCLI()) {
$logEntry->setCLIUser($this->console_info_helper->getCLIUser() ?? 'Unknown');
}
if ($this->shouldBeAdded($logEntry)) {
$this->em->persist($logEntry);