nettrine loggable neuklada username
- Felix
- Nette Core | 1245
Je to tak. Pridam k tomu i resource do dokumentace Gedmo – http://atlantic18.github.io/…oggable.html#….
Osobne bych to resil automaticky pres contributte/event-dispatcher-extra balicek. Kdy by se navesil event na application onRequest a nebo onPresenter.
Napriklad takto:
use Contributte\EventDispatcher\EventSubscriber;
use Contributte\Events\Extra\Event\Application\ApplicationEvents;
use Contributte\Events\Extra\Event\Application\RequestEvent;
use Gedmo\Loggable\LoggableListener;
use Nette\Security\User;
final class GedmoLoggableSubscriber implements EventSubscriber
{
/** @var LoggableListener */
private $loggableListener;
/** @var User */
private $user;
/**
* @return mixed[]
*/
public static function getSubscribedEvents(): array
{
return [
ApplicationEvents::ON_REQUEST => 'onRequest',
//ApplicationEvents::ON_PRESENTER => 'onPresenter',
];
}
public function onRequest(RequestEvent $event): void
{
if ($this->user->isLoggedIn()) {
$this->loggableListener->setUsername($this->user->getId());
} else {
$this->loggableListener->setUsername('Anonymous');
}
}
}