70 parent::__construct();
72 if (strpos(
$host,
':') !==
false) {
79 $this->socket =
false;
80 $this->closeOnError =
false;
81 $this->retryTime = null;
82 $this->retryStart = 1.0;
83 $this->retryMax = 30.0;
84 $this->retryFactor = 2.0;
85 $this->retryPeriod = 0;
121 if (!is_bool($close)) {
122 throw new \Plop\Exception(
'Invalid value');
124 $this->closeOnError = $close;
153 if (!(is_int($delay) || is_float($delay)) || $delay < 0) {
154 throw new \Plop\Exception(
'Invalid value');
156 $this->retryStart = $delay;
185 if (!(is_int($factor) || is_float($factor)) || $factor < 1) {
186 throw new \Plop\Exception(
'Invalid value');
188 $this->retryFactor = $factor;
217 if (!(is_int($max) || is_float($max)) || $max < 0) {
218 throw new \Plop\Exception(
'Invalid value');
220 $this->retryMax = $max;
239 'tcp://' . $this->host,
270 if ($this->retryTime === null) {
281 if ($this->socket !==
false) {
282 $this->retryTime = null;
286 if ($this->retryTime === null) {
290 if ($this->retryPeriod > $this->retryMax) {
312 if (!$this->socket) {
316 if (!$this->socket) {
322 $written = $this->
write($s);
323 if ($written ===
false) {
324 throw new \Plop\Exception(
'Connection lost');
326 $s = (string) substr($s, $written);
349 return @fwrite($this->socket, $s);
369 $s = serialize($record);
370 $slen = pack(
'N', strlen($s));
379 if ($this->closeOnError) {
382 return parent::handleError($record, $exception);
404 if (is_resource($this->socket)) {
405 fclose($this->socket);
407 $this->socket =
false;
handleError(\Plop\RecordInterface $record,\Exception $exception)
An abstract class that can be used as a base to create new log records handlers.
$socket
The socket that will be used to send the logs.
$retryMax
Maximum delay between reconnection attempts.
setInitialRetryDelay($delay)
$retryPeriod
The delay that will apply to the next reconnection attempt.
Interface for a log record.
An handler that sends log messages to a remote host over a TCP socket.
setMaximumRetryDelay($max)
emit(\Plop\RecordInterface $record)
$port
Remote port where the logs will be sent.
makePickle(\Plop\RecordInterface $record)
$retryTime
UNIX timestamp of the next connection attempt, if any.
__construct($host, $port)
$host
Remote host where the logs will be sent.
$retryStart
Initial delay for reconnection attempts.
This exception is thrown by Plop whenever a problem is detected.
__destruct()
Free the resources used by this handler.
$retryFactor
Factor applied to the reconnection delay after a reconnection failure.
$closeOnError
Whether to close the socket automatically on error.