DoctrineCouchDBHandler.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php declare(strict_types=1);
  2. /*
  3. * This file is part of the Monolog package.
  4. *
  5. * (c) Jordi Boggiano <j.boggiano@seld.be>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Monolog\Handler;
  11. use Monolog\Level;
  12. use Monolog\Formatter\NormalizerFormatter;
  13. use Monolog\Formatter\FormatterInterface;
  14. use Doctrine\CouchDB\CouchDBClient;
  15. use Monolog\LogRecord;
  16. /**
  17. * CouchDB handler for Doctrine CouchDB ODM
  18. *
  19. * @author Markus Bachmann <markus.bachmann@bachi.biz>
  20. */
  21. class DoctrineCouchDBHandler extends AbstractProcessingHandler
  22. {
  23. private CouchDBClient $client;
  24. public function __construct(CouchDBClient $client, int|string|Level $level = Level::Debug, bool $bubble = true)
  25. {
  26. $this->client = $client;
  27. parent::__construct($level, $bubble);
  28. }
  29. /**
  30. * @inheritDoc
  31. */
  32. protected function write(LogRecord $record): void
  33. {
  34. $this->client->postDocument($record->formatted);
  35. }
  36. protected function getDefaultFormatter(): FormatterInterface
  37. {
  38. return new NormalizerFormatter;
  39. }
  40. }