/** * {@inheritdoc} */ public function execute($command, callable $next) { $this->log($this->commandReceivedLogLevel, $this->formatter->commandReceived($command)); try { $returnValue = $next($command); } catch (Exception $e) { $this->log($this->commandFailedLogLevel, $this->formatter->commandFailed($command, $e)); throw $e; } $this->log($this->commandHandledLogLevel, $this->formatter->commandHandled($command)); return $returnValue; }
/** * @expectedException \League\Tactician\Logger\Tests\Fixtures\UserAlreadyExistsException */ public function testErrorLogLevelCanBeCustomized() { $middleware = new LoggerMiddleware($this->formatter, $this->logger, LogLevel::DEBUG, LogLevel::DEBUG, LogLevel::CRITICAL); $this->formatter->shouldReceive('commandReceived')->andReturn('received'); $this->formatter->shouldReceive('commandFailed')->andReturn('failed'); $this->logger->shouldReceive('log')->with(LogLevel::DEBUG, 'received'); $this->logger->shouldReceive('log')->with(LogLevel::CRITICAL, 'failed'); $middleware->execute(new RegisterUserCommand(), function () { throw new UserAlreadyExistsException(); }); }