/** * {@inheritdoc} * @throws \RuntimeException */ protected function write(array $record) { if (isset($record['formatted']) && is_array($record['formatted'])) { $record = $record['formatted']; } else { unset($record['formatted']); } try { $this->client->write($record); } catch (Lumberjack\Exception $ex) { $this->enabled = false; error_log($ex->getMessage()); } }
/** * @param array $logs */ public function processLogs($logs) { if (!$this->enabled) { return; } try { foreach ($this->formatLogs($logs) as $record) { $this->client->write($record); } } catch (Lumberjack\Exception $ex) { error_log((string) $ex); array_map('error_log', $logs); $this->enabled = false; } }
<?php require_once '../../vendor/autoload.php'; use Ekho\Logstash\Lumberjack; try { $client = new Lumberjack\Client(new Lumberjack\SecureSocket('127.0.0.1', 2323, array('ssl_cafile' => __DIR__ . '/resources/testssl.crt')), new Lumberjack\Encoder(), 5000); $client->write(array('line' => 'testmessage', 'param1' => date('Y-m-d H:i:s'))); } catch (RuntimeException $ex) { printf('Error #%d: %s%s', $ex->getCode(), $ex->getMessage(), PHP_EOL); // var_dump($ex); die('HAHAHAHAAHAHAHAHAHHAAHHAHAHHAHAH'); }