diff options
Diffstat (limited to 'library/Director/Daemon/JsonRpcLogWriter.php')
-rw-r--r-- | library/Director/Daemon/JsonRpcLogWriter.php | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/library/Director/Daemon/JsonRpcLogWriter.php b/library/Director/Daemon/JsonRpcLogWriter.php new file mode 100644 index 0000000..edfa23e --- /dev/null +++ b/library/Director/Daemon/JsonRpcLogWriter.php @@ -0,0 +1,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 + ]) + ); + } +} |