StdoutHandler.php 859 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace Yansongda\Supports\Logger;
  3. use Monolog\Handler\AbstractProcessingHandler;
  4. use Monolog\Logger;
  5. use Symfony\Component\Console\Output\ConsoleOutput;
  6. use Symfony\Component\Console\Output\OutputInterface;
  7. class StdoutHandler extends AbstractProcessingHandler
  8. {
  9. /**
  10. * @var OutputInterface
  11. */
  12. private $output;
  13. /**
  14. * Bootstrap.
  15. *
  16. * @param int $level
  17. * @param bool $bubble
  18. */
  19. public function __construct($level = Logger::DEBUG, $bubble = true, ?OutputInterface $output = null)
  20. {
  21. $this->output = $output ?? new ConsoleOutput();
  22. parent::__construct($level, $bubble);
  23. }
  24. /**
  25. * Writes the record down to the log of the implementing handler.
  26. */
  27. protected function write(array $record): void
  28. {
  29. $this->output->writeln($record['formatted']);
  30. }
  31. }