Skip to content

Commit 5ba350a

Browse files
committed
MAGETWO-67723: Add logging to contact us form #9343
- Merge Pull Request #9343 from JamesonNetworks/magento2:add_logging_to_contact_us
2 parents e0bd129 + 060e2e8 commit 5ba350a

File tree

1 file changed

+12
-2
lines changed
  • app/code/Magento/Contact/Controller/Index

1 file changed

+12
-2
lines changed

app/code/Magento/Contact/Controller/Index/Post.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Magento\Framework\Controller\Result\Redirect;
1515
use Magento\Framework\Exception\LocalizedException;
1616
use Magento\Framework\HTTP\PhpEnvironment\Request;
17+
use Psr\Log\LoggerInterface;
1718

1819
class Post extends \Magento\Contact\Controller\Index
1920
{
@@ -32,22 +33,30 @@ class Post extends \Magento\Contact\Controller\Index
3233
*/
3334
private $mail;
3435

36+
/**
37+
* @var LoggerInterface
38+
*/
39+
private $logger;
40+
3541
/**
3642
* @param Context $context
3743
* @param ConfigInterface $contactsConfig
3844
* @param MailInterface $mail
3945
* @param DataPersistorInterface $dataPersistor
46+
* @param LoggerInterface $logger
4047
*/
4148
public function __construct(
4249
Context $context,
4350
ConfigInterface $contactsConfig,
4451
MailInterface $mail,
45-
DataPersistorInterface $dataPersistor
52+
DataPersistorInterface $dataPersistor,
53+
LoggerInterface $logger = null
4654
) {
4755
parent::__construct($context, $contactsConfig);
4856
$this->context = $context;
4957
$this->mail = $mail;
5058
$this->dataPersistor = $dataPersistor;
59+
$this->logger = $logger ?: \Magento\Framework\App\ObjectManager::getInstance()->get(LoggerInterface::class);
5160
}
5261

5362
/**
@@ -70,8 +79,9 @@ public function execute()
7079
$this->messageManager->addErrorMessage($e->getMessage());
7180
$this->getDataPersistor()->set('contact_us', $this->getRequest()->getParams());
7281
} catch (\Exception $e) {
82+
$this->logger->critical($e);
7383
$this->messageManager->addErrorMessage(
74-
__('We can\'t process your request right now. Sorry, that\'s all we know.')
84+
__('An error occurred while processing your form. Please try again later.')
7585
);
7686
$this->getDataPersistor()->set('contact_us', $this->getRequest()->getParams());
7787
}

0 commit comments

Comments
 (0)