Syslog.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\Developer\Model\Logger\Handler;
  8. use Magento\Config\Setup\ConfigOptionsList;
  9. use Magento\Framework\App\Config\ScopeConfigInterface;
  10. use Magento\Framework\App\DeploymentConfig;
  11. /**
  12. * Enable/disable syslog logging based on the deployment config setting.
  13. */
  14. class Syslog extends \Magento\Framework\Logger\Handler\Syslog
  15. {
  16. /**
  17. * @deprecated configuration value has been removed.
  18. */
  19. public const CONFIG_PATH = 'dev/syslog/syslog_logging';
  20. /**
  21. * Deployment config.
  22. *
  23. * @var DeploymentConfig
  24. */
  25. private $deploymentConfig;
  26. /**
  27. * @param ScopeConfigInterface $scopeConfig Scope config
  28. * @param DeploymentConfig $deploymentConfig Deployment config
  29. * @param string $ident The string ident to be added to each message
  30. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  31. */
  32. public function __construct(
  33. ScopeConfigInterface $scopeConfig,
  34. DeploymentConfig $deploymentConfig,
  35. string $ident
  36. ) {
  37. parent::__construct($ident);
  38. $this->deploymentConfig = $deploymentConfig;
  39. }
  40. /**
  41. * @inheritdoc
  42. */
  43. public function isHandling(array $record): bool
  44. {
  45. return parent::isHandling($record)
  46. && $this->deploymentConfig->isDbAvailable()
  47. && $this->isLoggingEnabled();
  48. }
  49. /**
  50. * Check that logging functionality is enabled.
  51. *
  52. * @return bool
  53. */
  54. private function isLoggingEnabled(): bool
  55. {
  56. $configValue = $this->deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_SYSLOG_LOGGING);
  57. return (bool)$configValue;
  58. }
  59. }