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