summaryrefslogtreecommitdiffstats
path: root/library/Director/Daemon/LogProxy.php
blob: 0b58ae8ba013972cb69ccd4d8c90d9aeea798c38 (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php

namespace Icinga\Module\Director\Daemon;

use Exception;
use Icinga\Module\Director\Db;
use function React\Promise\resolve;

class LogProxy implements DbBasedComponent
{
    protected $connection;

    protected $db;

    protected $server;

    protected $instanceUuid;

    protected $prefix = '';

    public function __construct($instanceUuid)
    {
        $this->instanceUuid = $instanceUuid;
    }

    public function setPrefix($prefix)
    {
        $this->prefix = $prefix;

        return $this;
    }

    /**
     * @param Db $connection
     * @return \React\Promise\ExtendedPromiseInterface
     */
    public function initDb(Db $connection)
    {
        $this->connection = $connection;
        $this->db = $connection->getDbAdapter();

        return resolve();
    }

    /**
     * @return \React\Promise\ExtendedPromiseInterface
     */
    public function stopDb()
    {
        $this->connection = null;
        $this->db = null;

        return resolve();
    }

    public function log($severity, $message)
    {
        Logger::$severity($this->prefix . $message);
        /*
        // Not yet
        try {
            if ($this->db) {
                $this->db->insert('director_daemonlog', [
                    // environment/installation/db?
                    'instance_uuid' => $this->instanceUuid,
                    'ts_create'     => DaemonUtil::timestampWithMilliseconds(),
                    'level'         => $severity,
                    'message'       => $message,
                ]);
            }
        } catch (Exception $e) {
            Logger::error($e->getMessage());
        }
        */
    }
}