ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
Log_sql Class Reference
+ Inheritance diagram for Log_sql:
+ Collaboration diagram for Log_sql:

Public Member Functions

 Log_sql ($name, $ident='', $conf=array(), $level=PEAR_LOG_DEBUG)
 Constructs a new sql logging object. More...
 
 open ()
 Opens a connection to the database, if it has not already been opened. More...
 
 close ()
 Closes the connection to the database if it is still open and we were the ones that opened it. More...
 
 setIdent ($ident)
 Sets this Log instance's identification string. More...
 
 log ($message, $priority=null)
 Inserts $message to the currently open database. More...
 
 _prepareStatement ()
 Prepare the SQL insertion statement. 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

 $_dsn = ''
 
 $_sql = ''
 
 $_options = array('persistent' => true)
 
 $_db = null
 
 $_statement = null
 
 $_existingConnection = false
 
 $_table = 'log_table'
 
 $_sequence = 'log_id'
 
 $_identLimit = 16
 
- 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 43 of file sql.php.

Member Function Documentation

◆ _prepareStatement()

Log_sql::_prepareStatement ( )

Prepare the SQL insertion statement.

Returns
boolean True if the statement was successfully created.

@access private

Since
Log 1.9.1

Definition at line 287 of file sql.php.

288 {
289 $this->_statement = $this->_db->prepare($this->_sql);
290
291 /* Return success if we didn't generate an error. */
292 return (DB::isError($this->_statement) === false);
293 }

Referenced by log(), and open().

+ Here is the caller graph for this function:

◆ close()

Log_sql::close ( )

Closes the connection to the database if it is still open and we were the ones that opened it.

It is the caller's responsible to close an existing connection that was passed to us via $conf['db'].

Returns
boolean True on success, false on failure. @access public

Reimplemented from Log.

Definition at line 200 of file sql.php.

201 {
202 if ($this->_opened && !$this->_existingConnection) {
203 $this->_opened = false;
204 $this->_db->freePrepared($this->_statement);
205 return $this->_db->disconnect();
206 }
207
208 return ($this->_opened === false);
209 }

◆ log()

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

Inserts $message to the currently open database.

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.
string$priorityThe 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. @access public

Reimplemented from Log.

Definition at line 239 of file sql.php.

240 {
241 /* If a priority hasn't been specified, use the default value. */
242 if ($priority === null) {
243 $priority = $this->_priority;
244 }
245
246 /* Abort early if the priority is above the maximum logging level. */
247 if (!$this->_isMasked($priority)) {
248 return false;
249 }
250
251 /* If the connection isn't open and can't be opened, return failure. */
252 if (!$this->_opened && !$this->open()) {
253 return false;
254 }
255
256 /* If we don't already have our statement object yet, create it. */
257 if (!is_object($this->_statement) && !$this->_prepareStatement()) {
258 return false;
259 }
260
261 /* Extract the string representation of the message. */
262 $message = $this->_extractMessage($message);
263
264 /* Build our set of values for this log entry. */
265 $id = $this->_db->nextId($this->_sequence);
266 $values = array($id, $this->_ident, $priority, $message);
267
268 /* Execute the SQL query for this log entry insertion. */
269 $result =& $this->_db->execute($this->_statement, $values);
270 if (DB::isError($result)) {
271 return false;
272 }
273
274 $this->_announce(array('priority' => $priority, 'message' => $message));
275
276 return true;
277 }
$result
_prepareStatement()
Prepare the SQL insertion statement.
Definition: sql.php:287
open()
Opens a connection to the database, if it has not already been opened.
Definition: sql.php:171
$_priority
Definition: Log.php:69
_isMasked($priority)
Check if the given priority is included in the current level mask.
Definition: Log.php:726
_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

References Log\$_priority, $result, Log\_announce(), Log\_extractMessage(), Log\_isMasked(), _prepareStatement(), and open().

+ Here is the call graph for this function:

◆ Log_sql()

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

Constructs a new sql logging object.

Parameters
string$nameThe target SQL table.
string$identThe identification field.
array$confThe connection configuration array.
int$levelLog messages up to and including this level. @access public

Definition at line 120 of file sql.php.

122 {
123 $this->_id = md5(microtime());
124 $this->_table = $name;
125 $this->_mask = Log::UPTO($level);
126
127 /* Now that we have a table name, assign our SQL statement. */
128 if (!empty($conf['sql'])) {
129 $this->_sql = $conf['sql'];
130 } else {
131 $this->_sql = 'INSERT INTO ' . $this->_table .
132 ' (id, logtime, ident, priority, message)' .
133 ' VALUES(?, CURRENT_TIMESTAMP, ?, ?, ?)';
134 }
135
136 /* If an options array was provided, use it. */
137 if (isset($conf['options']) && is_array($conf['options'])) {
138 $this->_options = $conf['options'];
139 }
140
141 /* If a specific sequence name was provided, use it. */
142 if (!empty($conf['sequence'])) {
143 $this->_sequence = $conf['sequence'];
144 }
145
146 /* If a specific sequence name was provided, use it. */
147 if (isset($conf['identLimit'])) {
148 $this->_identLimit = $conf['identLimit'];
149 }
150
151 /* Now that the ident limit is confirmed, set the ident string. */
152 $this->setIdent($ident);
153
154 /* If an existing database connection was provided, use it. */
155 if (isset($conf['db'])) {
156 $this->_db = &$conf['db'];
157 $this->_existingConnection = true;
158 $this->_opened = true;
159 } else {
160 $this->_dsn = $conf['dsn'];
161 }
162 }
setIdent($ident)
Sets this Log instance's identification string.
Definition: sql.php:221
UPTO($priority)
Calculate the log mask for all priorities up to the given priority.
Definition: Log.php:642

References setIdent(), and Log\UPTO().

+ Here is the call graph for this function:

◆ open()

Log_sql::open ( )

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

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

Returns
boolean True on success, false on failure. @access public

Reimplemented from Log.

Definition at line 171 of file sql.php.

172 {
173 if (!$this->_opened) {
174 /* Use the DSN and options to create a database connection. */
175 $this->_db = &DB::connect($this->_dsn, $this->_options);
176 if (DB::isError($this->_db)) {
177 return false;
178 }
179
180 /* Create a prepared statement for repeated use in log(). */
181 if (!$this->_prepareStatement()) {
182 return false;
183 }
184
185 /* We now consider out connection open. */
186 $this->_opened = true;
187 }
188
189 return $this->_opened;
190 }
$_opened
Definition: Log.php:45

References Log\$_opened, and _prepareStatement().

Referenced by log().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setIdent()

Log_sql::setIdent (   $ident)

Sets this Log instance's identification string.

Note that this SQL-specific implementation will limit the length of the $ident string to sixteen (16) characters.

Parameters
string$identThe new identification string.

@access public

Since
Log 1.8.5

Reimplemented from Log.

Definition at line 221 of file sql.php.

222 {
223 $this->_ident = substr($ident, 0, $this->_identLimit);
224 }

Referenced by Log_sql().

+ Here is the caller graph for this function:

Field Documentation

◆ $_db

Log_sql::$_db = null

Definition at line 72 of file sql.php.

◆ $_dsn

Log_sql::$_dsn = ''

Definition at line 50 of file sql.php.

◆ $_existingConnection

Log_sql::$_existingConnection = false

Definition at line 86 of file sql.php.

◆ $_identLimit

Log_sql::$_identLimit = 16

Definition at line 108 of file sql.php.

◆ $_options

Log_sql::$_options = array('persistent' => true)

Definition at line 65 of file sql.php.

◆ $_sequence

Log_sql::$_sequence = 'log_id'

Definition at line 100 of file sql.php.

◆ $_sql

Log_sql::$_sql = ''

Definition at line 58 of file sql.php.

◆ $_statement

Log_sql::$_statement = null

Definition at line 79 of file sql.php.

◆ $_table

Log_sql::$_table = 'log_table'

Definition at line 93 of file sql.php.


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