ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
syslog.php
Go to the documentation of this file.
1<?php
23class Log_syslog extends Log
24{
30 var $_name = LOG_SYSLOG;
31
38 var $_inherit = false;
39
49 function Log_syslog($name, $ident = '', $conf = array(),
50 $level = PEAR_LOG_DEBUG)
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 }
67
73 function open()
74 {
75 if (!$this->_opened) {
76 $this->_opened = openlog($this->_ident, LOG_PID, $this->_name);
77 }
78
79 return $this->_opened;
80 }
81
86 function close()
87 {
88 if ($this->_opened && !$this->_inherit) {
89 closelog();
90 $this->_opened = false;
91 }
92
93 return true;
94 }
95
109 function log($message, $priority = null)
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 }
143
158 function _toSyslog($priority)
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 }
178
179}
const PEAR_LOG_ALERT
Definition: Log.php:11
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
const PEAR_LOG_INFO
Definition: Log.php:16
const PEAR_LOG_WARNING
Definition: Log.php:14
const PEAR_LOG_NOTICE
Definition: Log.php:15
open()
Opens a connection to the system logger, if it has not already been opened.
Definition: syslog.php:73
close()
Closes the connection to the system logger, if it is open.
Definition: syslog.php:86
log($message, $priority=null)
Sends $message to the currently open syslog connection.
Definition: syslog.php:109
Log_syslog($name, $ident='', $conf=array(), $level=PEAR_LOG_DEBUG)
Constructs a new syslog object.
Definition: syslog.php:49
_toSyslog($priority)
Converts a PEAR_LOG_* constant into a syslog LOG_* constant.
Definition: syslog.php:158
UPTO($priority)
Calculate the log mask for all priorities up to the given priority.
Definition: Log.php:642
$_priority
Definition: Log.php:69
_isMasked($priority)
Check if the given priority is included in the current level mask.
Definition: Log.php:726
$_opened
Definition: Log.php:45
_announce($event)
Informs each registered observer instance that a new message has been logged.
Definition: Log.php:811
_extractMessage($message)
Returns the string representation of the message data.
Definition: Log.php:417
The Log:: class implements both an abstraction for various logging mechanisms and the Subject end of ...