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

An handler that sends log messages to the system logs (syslog). More...

+ Inheritance diagram for Plop\Handler\SysLog:

Public Member Functions

 __construct ($address=self::DEFAULT_ADDRESS, $facility=LOG_USER)
 
 __destruct ()
 Free the resources used by this handler.
 
- 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)
 

Public Attributes

const DEFAULT_ADDRESS = 'udg:///dev/log'
 Default address for the system logs.
 
const LOG_FORMAT_STRING = "<%d>%s\000"
 Specific format string used for system logs.
 

Protected Member Functions

 close ()
 
 emit (\Plop\RecordInterface $record)
 
 encodePriority ($facility, $priority)
 
 makeSocket ()
 
 mapPriority ($levelName)
 
- Protected Member Functions inherited from Plop\HandlerAbstract
 emit (\Plop\RecordInterface $record)
 
 format (\Plop\RecordInterface $record)
 
 getStderr ()
 

Protected Attributes

 $address
 Address of the syslog where the logs will be sent.
 
 $facility
 The facility to use when logging the messages.
 
 $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.
 

Static Protected Attributes

static $facilityNames
 Mapping between the facility names and their associated constant. More...
 
static $priorityMap
 
static $priorityNames
 Mapping between Plop's log levels and the syslog ones. More...
 

Detailed Description

An handler that sends log messages to the system logs (syslog).

Definition at line 28 of file SysLog.php.

Constructor & Destructor Documentation

Plop\Handler\SysLog::__construct (   $address = self::DEFAULT_ADDRESS,
  $facility = LOG_USER 
)

Construct a new instance of this handler.

Parameters
string$address(optional) Address of the syslog daemon where the log messages will be sent, in the form "protocol://address:port". The default is to use the value of the Plop::Handler::SysLog::DEFAULT_ADDRESS constant, which sends logs to the local syslog daemon. IPv6 addresses must be enclosed in square brackets, eg. "tls://[fe80::1]:6514/".
int | string$facility(optional) The name or the value of the facility to use when sending the logs. By default, the "user" facility is used.

Definition at line 115 of file SysLog.php.

References Plop\Handler\SysLog\$address, Plop\Handler\SysLog\$facility, and Plop\Handler\SysLog\makeSocket().

Member Function Documentation

Plop\Handler\SysLog::close ( )
protected

Close the socket associated with this handler.

Returns
This method does not return any value.

Definition at line 191 of file SysLog.php.

Referenced by Plop\Handler\SysLog\__destruct().

Plop\Handler\SysLog::encodePriority (   $facility,
  $priority 
)
protected

Encode facility & priority information.

Parameters
int | string$facilityThe facility.
int | string$priorityThe priority.
Return values
intThe facility & priority, combined in a single integer.

Definition at line 174 of file SysLog.php.

References Plop\Handler\SysLog\$facility.

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

Plop\Handler\SysLog::makeSocket ( )
protected

Create the socket used to communicate with the syslog.

Return values
resourceThe newly-created socket.

Definition at line 156 of file SysLog.php.

Referenced by Plop\Handler\SysLog\__construct().

Plop\Handler\SysLog::mapPriority (   $levelName)
protected

Return the syslog priority associated with the given (Plop) level name.

Parameters
string$levelNameThe name of a log level defined in Plop.
Return values
stringThe syslog level to use to match the one given.

Definition at line 210 of file SysLog.php.

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

Member Data Documentation

Plop\Handler\SysLog::$facilityNames
staticprotected
Initial value:
= array(
'auth' => LOG_AUTH,
'authpriv' => LOG_AUTHPRIV,
'cron' => LOG_CRON,
'daemon' => LOG_DAEMON,
'kern' => LOG_KERN,
'lpr' => LOG_LPR,
'mail' => LOG_MAIL,
'news' => LOG_NEWS,
'syslog' => LOG_SYSLOG,
'user' => LOG_USER,
'uucp' => LOG_UUCP,
)

Mapping between the facility names and their associated constant.

Definition at line 53 of file SysLog.php.

Plop\Handler\SysLog::$priorityMap
staticprotected
Initial value:
= array(
'DEBUG' => 'debug',
'INFO' => 'info',
'NOTICE' => 'notice',
'WARNING' => 'warning',
'ERROR' => 'error',
'CRITICAL' => 'critical',
'ALERT' => 'alert',
'EMERGENCY' => 'emergency',
)

From python's logging/handlers.py : This map appears to be trivially lowercasing the key. However, there's more to it than meets the eye - in some locales, lowercasing gives unexpected results. See SF #1524081: in the Turkish locale,

"INFO".lower() != "info" 

The same is true for PHP.

Definition at line 76 of file SysLog.php.

Plop\Handler\SysLog::$priorityNames
staticprotected
Initial value:
= array(
'alert' => LOG_ALERT,
'crit' => LOG_CRIT,
'critical' => LOG_CRIT,
'debug' => LOG_DEBUG,
'emerg' => LOG_EMERG,
'err' => LOG_ERR,
'error' => LOG_ERR,
'info' => LOG_INFO,
'notice' => LOG_NOTICE,
'panic' => LOG_EMERG,
'warn' => LOG_WARNING,
'warning' => LOG_WARNING,
)

Mapping between Plop's log levels and the syslog ones.

Definition at line 37 of file SysLog.php.


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