StdoutHandler.php 831 B

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