System.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Logger\Handler;
  7. use Magento\Framework\Filesystem\DriverInterface;
  8. use Monolog\Logger;
  9. /**
  10. * System stream handler
  11. */
  12. class System extends Base
  13. {
  14. /**
  15. * @var string
  16. */
  17. protected $fileName = '/var/log/system.log';
  18. /**
  19. * @var int
  20. */
  21. protected $loggerType = Logger::INFO;
  22. /**
  23. * @var Exception
  24. */
  25. protected $exceptionHandler;
  26. /**
  27. * @param DriverInterface $filesystem
  28. * @param Exception $exceptionHandler
  29. * @param string $filePath
  30. */
  31. public function __construct(
  32. DriverInterface $filesystem,
  33. Exception $exceptionHandler,
  34. $filePath = null
  35. ) {
  36. $this->exceptionHandler = $exceptionHandler;
  37. parent::__construct($filesystem, $filePath);
  38. }
  39. /**
  40. * Writes formatted record through the handler.
  41. *
  42. * @param array $record The record metadata
  43. * @return void
  44. */
  45. public function write(array $record)
  46. {
  47. if (isset($record['context']['exception'])) {
  48. $this->exceptionHandler->handle($record);
  49. return;
  50. }
  51. $record['formatted'] = $this->getFormatter()->format($record);
  52. parent::write($record);
  53. }
  54. }