Source for file daemon.php
Documentation is available at daemon.php
// $Id: daemon.php,v 1.2 2005/02/26 14:48:58 chagenbu Exp $
* The Log_daemon class is a concrete implementation of the Log::
* abstract class which sends messages to syslog daemon on UNIX-like machines.
* This class uses the syslog protocol: http://www.ietf.org/rfc/rfc3164.txt
* @author Bart van der Schans <schans@dds.nl>
* @version $Revision: 1.2 $
* Integer holding the log facility to use.
* Var holding the resource pointer to the socket
* The ip address or servername
* @see http://www.php.net/manual/en/transports.php
* Protocol to use (tcp, udp, etc.)
* @see http://www.php.net/manual/en/transports.php
* Maximum message length in bytes
* Socket timeout in seconds
* Constructs a new syslog object.
* @param string $name The syslog facility.
* @param string $ident The identity string.
* @param array $conf The configuration array.
* @param int $maxLevel Maximum level at which to log.
function Log_daemon($name, $ident = '', $conf = array (),
/* Ensure we have a valid integer value for $name. */
if (empty ($name) || !is_int($name)) {
if (isset ($conf['ip'])) {
$this->_ip = $conf['ip'];
if (isset ($conf['proto'])) {
$this->_proto = $conf['proto'];
if (isset ($conf['port'])) {
$this->_port = $conf['port'];
if (isset ($conf['maxsize'])) {
$this->_maxsize = $conf['maxsize'];
if (isset ($conf['timeout'])) {
$this->_timeout = $conf['timeout'];
$this->_proto = $this->_proto . '://';
* Opens a connection to the system logger, if it has not already
* been opened. This is implicitly called by log(), if necessary.
$this->_opened = (bool) ($this->_socket = @fsockopen(
$this->_proto . $this->_ip,
* Closes the connection to the system logger, if it is open.
return fclose($this->_socket);
* Sends $message to the currently open syslog connection. Calls
* open() if necessary. Also passes the message along to any Log_observer
* instances that are observing this Log.
* @param string $message The textual message to be logged.
* @param int $priority (optional) The priority of the message. Valid
* values are: LOG_EMERG, LOG_ALERT, LOG_CRIT,
* LOG_ERR, LOG_WARNING, LOG_NOTICE, LOG_INFO,
* and LOG_DEBUG. The default is LOG_INFO.
function log($message, $priority = null )
/* If a priority hasn't been specified, use the default value. */
if ($priority === null ) {
$priority = $this->_priority;
/* Abort early if the priority is above the maximum logging level. */
if (!$this->_isMasked ($priority)) {
/* If the connection isn't open and can't be opened, return failure. */
if (!$this->_opened && !$this->open()) {
/* Extract the string representation of the message. */
$message = $this->_extractMessage ($message);
/* Set the facility level. */
$facility_level = intval($this->_name) +
intval($this->_toSyslog ($priority));
/* Prepend ident info. */
if (!empty ($this->_ident)) {
$message = $this->_ident . ' ' . $message;
/* Check for message length. */
if (strlen($message) > $this->_maxsize) {
$message = substr($message, 0 , ($this->_maxsize) - 10 ) . ' [...]';
fwrite($this->_socket, '<' . $facility_level . '>' . $message . "\n");
$this->_announce (array ('priority' => $priority, 'message' => $message));
* Converts a PEAR_LOG_* constant into a syslog LOG_* constant.
* This function exists because, under Windows, not all of the LOG_*
* constants have unique values. Instead, the PEAR_LOG_* were introduced
* for global use, with the conversion to the LOG_* constants kept local to
* @param int $priority PEAR_LOG_* value to convert to LOG_* value.
* @return The LOG_* representation of $priority.
function _toSyslog ($priority)
static $priorities = array (
PEAR_LOG_EMERG => LOG_EMERG ,
PEAR_LOG_ALERT => LOG_ALERT ,
PEAR_LOG_CRIT => LOG_CRIT ,
PEAR_LOG_WARNING => LOG_WARNING ,
PEAR_LOG_NOTICE => LOG_NOTICE ,
PEAR_LOG_INFO => LOG_INFO ,
PEAR_LOG_DEBUG => LOG_DEBUG
/* If we're passed an unknown priority, default to LOG_INFO. */
if (!is_int ($priority) || !in_array ($priority, $priorities)) {
return $priorities[$priority];
Documentation generated on Mon, 11 Mar 2019 14:42:39 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|