Debug.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Developer\Model\Logger\Handler;
  7. use Magento\Config\Setup\ConfigOptionsList;
  8. use Magento\Framework\App\Config\ScopeConfigInterface;
  9. use Magento\Framework\App\State;
  10. use Magento\Framework\Filesystem\DriverInterface;
  11. use Magento\Framework\App\DeploymentConfig;
  12. /**
  13. * Enable/disable debug logging based on the store config setting
  14. */
  15. class Debug extends \Magento\Framework\Logger\Handler\Debug
  16. {
  17. /**
  18. * @var State
  19. */
  20. private $state;
  21. /**
  22. * @var ScopeConfigInterface
  23. */
  24. private $scopeConfig;
  25. /**
  26. * @var DeploymentConfig
  27. */
  28. private $deploymentConfig;
  29. /**
  30. * @param DriverInterface $filesystem
  31. * @param State $state
  32. * @param ScopeConfigInterface $scopeConfig
  33. * @param DeploymentConfig $deploymentConfig
  34. * @param string $filePath
  35. * @throws \Exception
  36. */
  37. public function __construct(
  38. DriverInterface $filesystem,
  39. State $state,
  40. ScopeConfigInterface $scopeConfig,
  41. DeploymentConfig $deploymentConfig,
  42. $filePath = null
  43. ) {
  44. parent::__construct($filesystem, $filePath);
  45. $this->state = $state;
  46. $this->scopeConfig = $scopeConfig;
  47. $this->deploymentConfig = $deploymentConfig;
  48. }
  49. /**
  50. * @inheritdoc
  51. */
  52. public function isHandling(array $record)
  53. {
  54. if ($this->deploymentConfig->isAvailable()) {
  55. return
  56. parent::isHandling($record)
  57. && $this->isLoggingEnabled();
  58. }
  59. return parent::isHandling($record);
  60. }
  61. /**
  62. * Check that logging functionality is enabled.
  63. *
  64. * @return bool
  65. */
  66. private function isLoggingEnabled(): bool
  67. {
  68. $configValue = $this->deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_DEBUG_LOGGING);
  69. if ($configValue === null) {
  70. $isEnabled = $this->state->getMode() !== State::MODE_PRODUCTION;
  71. } else {
  72. $isEnabled = (bool)$configValue;
  73. }
  74. return $isEnabled;
  75. }
  76. }