ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
All Data Structures Namespaces Files Functions Variables Modules Pages
Log_syslog Class Reference
+ Inheritance diagram for Log_syslog:
+ Collaboration diagram for Log_syslog:

Public Member Functions

 Log_syslog ($name, $ident='', $conf=array(), $level=PEAR_LOG_DEBUG)
 Constructs a new syslog object. More...
 
 open ()
 Opens a connection to the system logger, if it has not already been opened. More...
 
 close ()
 Closes the connection to the system logger, if it is open. More...
 
 log ($message, $priority=null)
 Sends $message to the currently open syslog connection. More...
 
 _toSyslog ($priority)
 Converts a PEAR_LOG_* constant into a syslog LOG_* constant. More...
 
- Public Member Functions inherited from Log
 _classExists ($class)
 Utility function which wraps PHP's class_exists() function to ensure consistent behavior between PHP versions 4 and 5. More...
 
factory ($handler, $name='', $ident='', $conf=array(), $level=PEAR_LOG_DEBUG)
 Attempts to return a concrete Log instance of type $handler. More...
 
singleton ($handler, $name='', $ident='', $conf=array(), $level=PEAR_LOG_DEBUG)
 Attempts to return a reference to a concrete Log instance of type $handler, only creating a new instance if no log instance with the same parameters currently exists. More...
 
 open ()
 Abstract implementation of the open() method. More...
 
 close ()
 Abstract implementation of the close() method. More...
 
 flush ()
 Abstract implementation of the flush() method. More...
 
 log ($message, $priority=null)
 Abstract implementation of the log() method. More...
 
 emerg ($message)
 A convenience function for logging a emergency event. More...
 
 alert ($message)
 A convenience function for logging an alert event. More...
 
 crit ($message)
 A convenience function for logging a critical event. More...
 
 err ($message)
 A convenience function for logging a error event. More...
 
 warning ($message)
 A convenience function for logging a warning event. More...
 
 notice ($message)
 A convenience function for logging a notice event. More...
 
 info ($message)
 A convenience function for logging a information event. More...
 
 debug ($message)
 A convenience function for logging a debug event. More...
 
 _extractMessage ($message)
 Returns the string representation of the message data. More...
 
 _getBacktraceVars ($depth)
 Using debug_backtrace(), returns the file, line, and enclosing function name of the source code context from which log() was invoked. More...
 
 _format ($format, $timestamp, $priority, $message)
 Produces a formatted log line based on a format string and a set of variables representing the current log record and state. More...
 
 priorityToString ($priority)
 Returns the string representation of a PEAR_LOG_* integer constant. More...
 
 stringToPriority ($name)
 Returns the the PEAR_LOG_* integer constant for the given string representation of a priority name. More...
 
 MASK ($priority)
 Calculate the log mask for the given priority. More...
 
 UPTO ($priority)
 Calculate the log mask for all priorities up to the given priority. More...
 
 MIN ($priority)
 Calculate the log mask for all priorities greater than or equal to the given priority. More...
 
 MAX ($priority)
 Calculate the log mask for all priorities less than or equal to the given priority. More...
 
 setMask ($mask)
 Set and return the level mask for the current Log instance. More...
 
 getMask ()
 Returns the current level mask. More...
 
 _isMasked ($priority)
 Check if the given priority is included in the current level mask. More...
 
 getPriority ()
 Returns the current default priority. More...
 
 setPriority ($priority)
 Sets the default priority to the specified value. More...
 
 attach (&$observer)
 Adds a Log_observer instance to the list of observers that are listening for messages emitted by this Log instance. More...
 
 detach ($observer)
 Removes a Log_observer instance from the list of observers. More...
 
 _announce ($event)
 Informs each registered observer instance that a new message has been logged. More...
 
 isComposite ()
 Indicates whether this is a composite class. More...
 
 setIdent ($ident)
 Sets this Log instance's identification string. More...
 
 getIdent ()
 Returns the current identification string. More...
 

Data Fields

 $_name = LOG_SYSLOG
 
 $_inherit = false
 
- Data Fields inherited from Log
 $_opened = false
 
 $_id = 0
 
 $_ident = ''
 
 $_priority = PEAR_LOG_INFO
 
 $_mask = PEAR_LOG_ALL
 
 $_listeners = array()
 
 $_formatMap
 

Detailed Description

Definition at line 23 of file syslog.php.

Member Function Documentation

◆ _toSyslog()

Log_syslog::_toSyslog (   $priority)

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 to the syslog driver.

Parameters
int$priorityPEAR_LOG_* value to convert to LOG_* value.
Returns
The LOG_* representation of $priority.

private

Definition at line 158 of file syslog.php.

References PEAR_LOG_ALERT, PEAR_LOG_CRIT, PEAR_LOG_DEBUG, PEAR_LOG_EMERG, PEAR_LOG_ERR, PEAR_LOG_INFO, PEAR_LOG_NOTICE, and PEAR_LOG_WARNING.

Referenced by log().

159  {
160  static $priorities = array(
161  PEAR_LOG_EMERG => LOG_EMERG,
162  PEAR_LOG_ALERT => LOG_ALERT,
163  PEAR_LOG_CRIT => LOG_CRIT,
164  PEAR_LOG_ERR => LOG_ERR,
165  PEAR_LOG_WARNING => LOG_WARNING,
166  PEAR_LOG_NOTICE => LOG_NOTICE,
167  PEAR_LOG_INFO => LOG_INFO,
168  PEAR_LOG_DEBUG => LOG_DEBUG
169  );
170 
171  /* If we're passed an unknown priority, default to LOG_INFO. */
172  if (!is_int($priority) || !in_array($priority, $priorities)) {
173  return LOG_INFO;
174  }
175 
176  return $priorities[$priority];
177  }
const PEAR_LOG_ALERT
Definition: Log.php:11
const PEAR_LOG_INFO
Definition: Log.php:16
const PEAR_LOG_WARNING
Definition: Log.php:14
const PEAR_LOG_NOTICE
Definition: Log.php:15
const PEAR_LOG_EMERG
Definition: Log.php:10
const PEAR_LOG_ERR
Definition: Log.php:13
const PEAR_LOG_CRIT
Definition: Log.php:12
const PEAR_LOG_DEBUG
Definition: Log.php:17
+ Here is the caller graph for this function:

◆ close()

Log_syslog::close ( )

Closes the connection to the system logger, if it is open.

public

Definition at line 86 of file syslog.php.

87  {
88  if ($this->_opened && !$this->_inherit) {
89  closelog();
90  $this->_opened = false;
91  }
92 
93  return true;
94  }

◆ log()

Log_syslog::log (   $message,
  $priority = null 
)

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.

Parameters
mixed$messageString or object containing the message to log.
int$priority(optional) The priority of the message. Valid values are: PEAR_LOG_EMERG, PEAR_LOG_ALERT, PEAR_LOG_CRIT, PEAR_LOG_ERR, PEAR_LOG_WARNING, PEAR_LOG_NOTICE, PEAR_LOG_INFO, and PEAR_LOG_DEBUG.
Returns
boolean True on success or false on failure. public

Definition at line 109 of file syslog.php.

References $_name, Log\$_priority, Log\_announce(), Log\_extractMessage(), Log\_isMasked(), _toSyslog(), and open().

110  {
111  /* If a priority hasn't been specified, use the default value. */
112  if ($priority === null) {
113  $priority = $this->_priority;
114  }
115 
116  /* Abort early if the priority is above the maximum logging level. */
117  if (!$this->_isMasked($priority)) {
118  return false;
119  }
120 
121  /* If the connection isn't open and can't be opened, return failure. */
122  if (!$this->_opened && !$this->open()) {
123  return false;
124  }
125 
126  /* Extract the string representation of the message. */
127  $message = $this->_extractMessage($message);
128 
129  /* Build a syslog priority value based on our current configuration. */
130  $priority = $this->_toSyslog($priority);
131  if ($this->_inherit) {
132  $priority |= $this->_name;
133  }
134 
135  if (!syslog($priority, $message)) {
136  return false;
137  }
138 
139  $this->_announce(array('priority' => $priority, 'message' => $message));
140 
141  return true;
142  }
_announce($event)
Informs each registered observer instance that a new message has been logged.
Definition: Log.php:811
_toSyslog($priority)
Converts a PEAR_LOG_* constant into a syslog LOG_* constant.
Definition: syslog.php:158
$_priority
Definition: Log.php:69
_isMasked($priority)
Check if the given priority is included in the current level mask.
Definition: Log.php:726
_extractMessage($message)
Returns the string representation of the message data.
Definition: Log.php:417
open()
Opens a connection to the system logger, if it has not already been opened.
Definition: syslog.php:73
+ Here is the call graph for this function:

◆ Log_syslog()

Log_syslog::Log_syslog (   $name,
  $ident = '',
  $conf = array(),
  $level = PEAR_LOG_DEBUG 
)

Constructs a new syslog object.

Parameters
string$nameThe syslog facility.
string$identThe identity string.
array$confThe configuration array.
int$levelLog messages up to and including this level. public

Definition at line 49 of file syslog.php.

References $_inherit, and Log\UPTO().

51  {
52  /* Ensure we have a valid integer value for $name. */
53  if (empty($name) || !is_int($name)) {
54  $name = LOG_SYSLOG;
55  }
56 
57  if (isset($conf['inherit'])) {
58  $this->_inherit = $conf['inherit'];
59  $this->_opened = $this->_inherit;
60  }
61 
62  $this->_id = md5(microtime());
63  $this->_name = $name;
64  $this->_ident = $ident;
65  $this->_mask = Log::UPTO($level);
66  }
UPTO($priority)
Calculate the log mask for all priorities up to the given priority.
Definition: Log.php:642
+ Here is the call graph for this function:

◆ open()

Log_syslog::open ( )

Opens a connection to the system logger, if it has not already been opened.

This is implicitly called by log(), if necessary. public

Definition at line 73 of file syslog.php.

References Log\$_opened.

Referenced by log().

74  {
75  if (!$this->_opened) {
76  $this->_opened = openlog($this->_ident, LOG_PID, $this->_name);
77  }
78 
79  return $this->_opened;
80  }
$_opened
Definition: Log.php:45
+ Here is the caller graph for this function:

Field Documentation

◆ $_inherit

Log_syslog::$_inherit = false

Definition at line 38 of file syslog.php.

Referenced by Log_syslog().

◆ $_name

Log_syslog::$_name = LOG_SYSLOG

Definition at line 30 of file syslog.php.

Referenced by log().


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