summaryrefslogtreecommitdiffstats
path: root/library/Director/Daemon/JsonRpcLogWriter.php
blob: edfa23e2d2d6670bec31f514739fcbe27a19dcc9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php

namespace Icinga\Module\Director\Daemon;

use gipfl\Protocol\JsonRpc\Connection;
use gipfl\Protocol\JsonRpc\Notification;
use Icinga\Application\Logger\LogWriter;
use Icinga\Data\ConfigObject;

class JsonRpcLogWriter extends LogWriter
{
    protected $connection;

    protected static $severityMap = [
        Logger::DEBUG   => 'debug',
        Logger::INFO    => 'info',
        Logger::WARNING => 'warning',
        Logger::ERROR   => 'error',
    ];

    public function __construct(Connection $connection)
    {
        parent::__construct(new ConfigObject([]));
        $this->connection = $connection;
    }

    public function log($severity, $message)
    {
        $message = \iconv('UTF-8', 'UTF-8//IGNORE', $message);
        $this->connection->sendNotification(
            Notification::create('logger.log', [
                static::$severityMap[$severity],
                $message
            ])
        );
    }
}