InvalidateLogger.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * Cache configuration model. Provides cache configuration data to the application
  4. *
  5. * Copyright © Magento, Inc. All rights reserved.
  6. * See COPYING.txt for license details.
  7. */
  8. namespace Magento\Framework\Cache;
  9. use Magento\Framework\App\Request\Http as HttpRequest;
  10. use Psr\Log\LoggerInterface as Logger;
  11. class InvalidateLogger
  12. {
  13. /**
  14. * @var HttpRequest
  15. */
  16. private $request;
  17. /**
  18. * @var Logger
  19. */
  20. private $logger;
  21. /**
  22. * @param HttpRequest $request
  23. * @param Logger $logger
  24. */
  25. public function __construct(HttpRequest $request, Logger $logger)
  26. {
  27. $this->request = $request;
  28. $this->logger = $logger;
  29. }
  30. /**
  31. * Logger invalidate cache
  32. * @param mixed $invalidateInfo
  33. * @return void
  34. */
  35. public function execute($invalidateInfo)
  36. {
  37. $this->logger->debug('cache_invalidate: ', $this->makeParams($invalidateInfo));
  38. }
  39. /**
  40. * Make extra data to logger message
  41. * @param mixed $invalidateInfo
  42. * @return array
  43. */
  44. private function makeParams($invalidateInfo)
  45. {
  46. $method = $this->request->getMethod();
  47. $url = $this->request->getUriString();
  48. return compact('method', 'url', 'invalidateInfo');
  49. }
  50. /**
  51. * Log critical
  52. *
  53. * @param string $message
  54. * @param mixed $params
  55. * @return void
  56. */
  57. public function critical($message, $params)
  58. {
  59. $this->logger->critical($message, $this->makeParams($params));
  60. }
  61. }