Plop
A simple logging library for PHP
Plop\Handler\Socket Class Reference

An handler that sends log messages to a remote host over a TCP socket. More...

+ Inheritance diagram for Plop\Handler\Socket:

Public Member Functions

 __construct ($host, $port)
 
 __destruct ()
 Free the resources used by this handler.
 
 getCloseOnError ()
 
 getInitialRetryDelay ()
 
 getMaximumRetryDelay ()
 
 getRetryFactor ()
 
 handleError (\Plop\RecordInterface $record,\Exception $exception)
 
 setCloseOnError ($close)
 
 setInitialRetryDelay ($delay)
 
 setMaximumRetryDelay ($max)
 
 setRetryFactor ($factor)
 
- Public Member Functions inherited from Plop\HandlerAbstract
 __construct (\Plop\FormatterInterface $formatter=null,\Plop\FiltersCollectionAbstract $filters=null)
 
 getFilters ()
 
 getFormatter ()
 
 handle (\Plop\RecordInterface $record)
 
 handleError (\Plop\RecordInterface $record,\Exception $exception)
 
 setFilters (\Plop\FiltersCollectionAbstract $filters)
 
 setFormatter (\Plop\FormatterInterface $formatter)
 

Protected Member Functions

 close ()
 
 createSocket ()
 
 emit (\Plop\RecordInterface $record)
 
 getCurrentTime ()
 
 makePickle (\Plop\RecordInterface $record)
 
 makeSocket ($timeout=1)
 
 send ($s)
 
 write ($s)
 
- Protected Member Functions inherited from Plop\HandlerAbstract
 emit (\Plop\RecordInterface $record)
 
 format (\Plop\RecordInterface $record)
 
 getStderr ()
 

Protected Attributes

 $closeOnError
 Whether to close the socket automatically on error.
 
 $host
 Remote host where the logs will be sent.
 
 $port
 Remote port where the logs will be sent.
 
 $retryFactor
 Factor applied to the reconnection delay after a reconnection failure.
 
 $retryMax
 Maximum delay between reconnection attempts.
 
 $retryPeriod
 The delay that will apply to the next reconnection attempt.
 
 $retryStart
 Initial delay for reconnection attempts.
 
 $retryTime
 UNIX timestamp of the next connection attempt, if any.
 
 $socket
 The socket that will be used to send the logs.
 
- Protected Attributes inherited from Plop\HandlerAbstract
 $filters
 An object handling a collection of filters.
 
 $formatter
 Formatter object to use for this handler.
 

Detailed Description

An handler that sends log messages to a remote host over a TCP socket.

Definition at line 28 of file Socket.php.

Constructor & Destructor Documentation

Plop\Handler\Socket::__construct (   $host,
  $port 
)

Construct a new instance of this handler.

Parameters
string$hostThe remote host where the logs will be sent. This may be a (fully qualified) host name or an IP address (v4 or v6).
int$portDestination port where the logs will be sent.

Definition at line 68 of file Socket.php.

References Plop\Handler\Socket\$host, and Plop\Handler\Socket\$port.

Member Function Documentation

Plop\Handler\Socket::close ( )
protected

Close the socket associated with this handler.

Returns
This method does not return any value.

Definition at line 402 of file Socket.php.

Referenced by Plop\Handler\Socket\__destruct(), and Plop\Handler\Socket\handleError().

Plop\Handler\Socket::createSocket ( )
protected

Create a new socket, taking into account things like retry attempts and delays.

Returns
This method does not return any value.

Definition at line 267 of file Socket.php.

References Plop\Handler\Socket\$retryFactor, Plop\Handler\Socket\$retryMax, Plop\Handler\Socket\$retryPeriod, Plop\Handler\Socket\$retryStart, Plop\Handler\Socket\$retryTime, Plop\Handler\Socket\getCurrentTime(), and Plop\Handler\Socket\makeSocket().

Referenced by Plop\Handler\Socket\send().

Plop\Handler\Socket::emit ( \Plop\RecordInterface  $record)
protected
Plop\Handler\Socket::getCloseOnError ( )

Return whether the socket is closed automatically after an error.

Return values
boolWhether the socket is closed automatically on error (true) or not (false).

Definition at line 103 of file Socket.php.

References Plop\Handler\Socket\$closeOnError.

Plop\Handler\Socket::getCurrentTime ( )
protected

Return the current time as a UNIX timestamp.

Return values
intThe current time, as a UNIX timestamp.

Definition at line 255 of file Socket.php.

Referenced by Plop\Handler\Socket\createSocket().

Plop\Handler\Socket::getInitialRetryDelay ( )

Return the delay for the initial reconnection attempt.

Return values
int|floatInitial delay for reconnection attempts.

Definition at line 135 of file Socket.php.

References Plop\Handler\Socket\$retryStart.

Plop\Handler\Socket::getMaximumRetryDelay ( )

Return the maximum delay between reconnection attempts.

Return values
int|floatMaximum delay between reconnection attempts.

Definition at line 199 of file Socket.php.

References Plop\Handler\Socket\$retryMax.

Plop\Handler\Socket::getRetryFactor ( )

Return the current delay factor between reconnection attempts.

Return values
int|floatCurrent delay factor.

Definition at line 167 of file Socket.php.

References Plop\Handler\Socket\$retryFactor.

Plop\Handler\Socket::handleError ( \Plop\RecordInterface  $record,
\Exception  $exception 
)

Implements Plop\HandlerInterface.

Definition at line 375 of file Socket.php.

References Plop\Handler\Socket\close().

Referenced by Plop\Handler\Socket\emit().

Plop\Handler\Socket::makePickle ( \Plop\RecordInterface  $record)
protected

Serialize and format a log record so that it can be sent through the wire.

Parameters
Plop::RecordInterface$recordThe record to serialize.
Return values
stringSerialized representation of the record, with additional metadata.

Definition at line 363 of file Socket.php.

Referenced by Plop\Handler\Socket\emit().

Plop\Handler\Socket::makeSocket (   $timeout = 1)
protected

Really create a new socket.

Parameters
int$timeout(optional) Timeout for the connection, in seconds. Defaults to 1 second.
Return values
resourceThe newly created socket.

Definition at line 236 of file Socket.php.

Referenced by Plop\Handler\Socket\createSocket().

Plop\Handler\Socket::send (   $s)
protected

Send the given string over the wire.

Parameters
string$sThe text to send over.
Return values
boolWhether a connection could be established and the data sent properly.
Exceptions
Plop::ExceptionThe connection was lost during the transmission.

Definition at line 310 of file Socket.php.

References Plop\Handler\Socket\createSocket(), and Plop\Handler\Socket\write().

Referenced by Plop\Handler\Socket\emit().

Plop\Handler\Socket::setCloseOnError (   $close)

Set whether the socket must be closed automatically on error.

Parameters
bool$closeThe socket will be closed on error if this is true.
Return values
Plop::HandlerInterfaceThe current handler instance (ie. $this).

Definition at line 119 of file Socket.php.

Plop\Handler\Socket::setInitialRetryDelay (   $delay)

Set the delay for the initial reconnection attempt.

Parameters
int | float$delayInitial delay for reconnection attempts. This value must be a non-negative number.
Return values
Plop::HandlerInterfaceThe current handler instance (ie. $this).

Definition at line 151 of file Socket.php.

Plop\Handler\Socket::setMaximumRetryDelay (   $max)

Set the maximum delay between reconnection attempts.

Parameters
int | float$maxMaximum delay between reconnection attempts. This value must be a non-negative number.
Return values
Plop::HandlerInterfaceThe current handler instance (ie. $this).

Definition at line 215 of file Socket.php.

Plop\Handler\Socket::setRetryFactor (   $factor)

Set the factor applied to the delay between each reconnection attempt.

Parameters
int | float$factorDelay factor. This value must be greater or equal to 1.
Return values
Plop::HandlerInterfaceThe current handler instance (ie. $this).

Definition at line 183 of file Socket.php.

Plop\Handler\Socket::write (   $s)
protected

Write data to the underlying stream.

Parameters
string$sData to write.
Return values
false|intReturn the number of bytes written to the underlying stream (which can be less than the length of the data given due to buffering) or false in case of an error (eg. connection lost).

Definition at line 347 of file Socket.php.

Referenced by Plop\Handler\Socket\send().


The documentation for this class was generated from the following file: