ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
Log_mdb2 Class Reference
+ Inheritance diagram for Log_mdb2:
+ Collaboration diagram for Log_mdb2:

Public Member Functions

 Log_mdb2 ($name, $ident= '', $conf=array(), $level=PEAR_LOG_DEBUG)
 Constructs a new sql logging object.
 open ()
 Opens a connection to the database, if it has not already been opened.
 close ()
 Closes the connection to the database if it is still open and we were the ones that opened it.
 setIdent ($ident)
 Sets this Log instance's identification string.
 log ($message, $priority=null)
 Inserts $message to the currently open database.
 _createTable ()
 Create the log table in the database.
 _prepareStatement ()
 Prepare the SQL insertion statement.
- 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.
factory ($handler, $name= '', $ident= '', $conf=array(), $level=PEAR_LOG_DEBUG)
 Attempts to return a concrete Log instance of type $handler.
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.
 flush ()
 Abstract implementation of the flush() method.
 emerg ($message)
 A convenience function for logging a emergency event.
 alert ($message)
 A convenience function for logging an alert event.
 crit ($message)
 A convenience function for logging a critical event.
 err ($message)
 A convenience function for logging a error event.
 warning ($message)
 A convenience function for logging a warning event.
 notice ($message)
 A convenience function for logging a notice event.
 info ($message)
 A convenience function for logging a information event.
 debug ($message)
 A convenience function for logging a debug event.
 _extractMessage ($message)
 Returns the string representation of the message data.
 _getBacktraceVars ($depth)
 Using debug_backtrace(), returns the file, line, and enclosing function name of the source code context from which log() was invoked.
 _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.
 priorityToString ($priority)
 Returns the string representation of a PEAR_LOG_* integer constant.
 stringToPriority ($name)
 Returns the the PEAR_LOG_* integer constant for the given string representation of a priority name.
 MASK ($priority)
 Calculate the log mask for the given priority.
 UPTO ($priority)
 Calculate the log mask for all priorities up to the given priority.
 MIN ($priority)
 Calculate the log mask for all priorities greater than or equal to the given priority.
 MAX ($priority)
 Calculate the log mask for all priorities less than or equal to the given priority.
 setMask ($mask)
 Set and return the level mask for the current Log instance.
 getMask ()
 Returns the current level mask.
 _isMasked ($priority)
 Check if the given priority is included in the current level mask.
 getPriority ()
 Returns the current default priority.
 setPriority ($priority)
 Sets the default priority to the specified value.
 attach (&$observer)
 Adds a Log_observer instance to the list of observers that are listening for messages emitted by this Log instance.
 detach ($observer)
 Removes a Log_observer instance from the list of observers.
 _announce ($event)
 Informs each registered observer instance that a new message has been logged.
 isComposite ()
 Indicates whether this is a composite class.
 getIdent ()
 Returns the current identification string.

Data Fields

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

Member Function Documentation

Log_mdb2::_createTable ( )

Create the log table in the database.

Returns
boolean True on success or false on failure. private

Definition at line 310 of file mdb2.php.

References $result, and PEAR\isError().

Referenced by log().

{
$this->_db->loadModule('Manager', null, true);
$result = $this->_db->manager->createTable(
$this->_table,
array(
'id' => array('type' => $this->_types['id']),
'logtime' => array('type' => $this->_types['logtime']),
'ident' => array('type' => $this->_types['ident']),
'priority' => array('type' => $this->_types['priority']),
'message' => array('type' => $this->_types['message'])
)
);
return false;
}
$result = $this->_db->manager->createIndex(
$this->_table,
'unique_id',
array('fields' => array('id' => true), 'unique' => true)
);
return false;
}
return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Log_mdb2::_prepareStatement ( )

Prepare the SQL insertion statement.

Returns
boolean True if the statement was successfully created.

private

Since
Log 1.9.0

Definition at line 347 of file mdb2.php.

References PEAR\isError(), and MDB2_PREPARE_MANIP.

Referenced by log(), and open().

{
$this->_statement = &$this->_db->prepare(
'INSERT INTO ' . $this->_table .
' (id, logtime, ident, priority, message)' .
' VALUES(:id, :logtime, :ident, :priority, :message)',
$this->_types, MDB2_PREPARE_MANIP);
/* Return success if we didn't generate an error. */
return (PEAR::isError($this->_statement) === false);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Log_mdb2::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. public

Reimplemented from Log.

Definition at line 190 of file mdb2.php.

{
/* If we have a statement object, free it. */
if (is_object($this->_statement)) {
$this->_statement->free();
$this->_statement = null;
}
/* If we opened the database connection, disconnect it. */
if ($this->_opened && !$this->_existingConnection) {
$this->_opened = false;
return $this->_db->disconnect();
}
return ($this->_opened === false);
}
Log_mdb2::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. public

Reimplemented from Log.

Definition at line 235 of file mdb2.php.

References Log\$_ident, Log\$_priority, $result, Log\_announce(), _createTable(), Log\_extractMessage(), Log\_isMasked(), _prepareStatement(), PEAR\isError(), MDB2_ERROR_NOSUCHTABLE, MDB2_Date\mdbNow(), and open().

{
/* 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)) {
return false;
}
/* If the connection isn't open and can't be opened, return failure. */
if (!$this->_opened && !$this->open()) {
return false;
}
/* If we don't already have a statement object, create one. */
if (!is_object($this->_statement) && !$this->_prepareStatement()) {
return false;
}
/* Extract the string representation of the message. */
$message = $this->_extractMessage($message);
/* Build our set of values for this log entry. */
$values = array(
'id' => $this->_db->nextId($this->_sequence),
'logtime' => MDB2_Date::mdbNow(),
'ident' => $this->_ident,
'priority' => $priority,
'message' => $message
);
/* Execute the SQL query for this log entry insertion. */
$this->_db->expectError(MDB2_ERROR_NOSUCHTABLE);
$result = &$this->_statement->execute($values);
$this->_db->popExpect();
/* Attempt to handle any errors. */
/* We can only handle MDB2_ERROR_NOSUCHTABLE errors. */
if ($result->getCode() != MDB2_ERROR_NOSUCHTABLE) {
return false;
}
/* Attempt to create the target table. */
if (!$this->_createTable()) {
return false;
}
/* Recreate our prepared statement resource. */
$this->_statement->free();
if (!$this->_prepareStatement()) {
return false;
}
/* Attempt to re-execute the insertion query. */
$result = $this->_statement->execute($values);
return false;
}
}
$this->_announce(array('priority' => $priority, 'message' => $message));
return true;
}

+ Here is the call graph for this function:

Log_mdb2::Log_mdb2 (   $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. public

Definition at line 115 of file mdb2.php.

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

{
$this->_id = md5(microtime());
$this->_table = $name;
$this->_mask = Log::UPTO($level);
/* If an options array was provided, use it. */
if (isset($conf['options']) && is_array($conf['options'])) {
$this->_options = $conf['options'];
}
/* If a specific sequence name was provided, use it. */
if (!empty($conf['sequence'])) {
$this->_sequence = $conf['sequence'];
}
/* If a specific sequence name was provided, use it. */
if (isset($conf['identLimit'])) {
$this->_identLimit = $conf['identLimit'];
}
/* Now that the ident limit is confirmed, set the ident string. */
$this->setIdent($ident);
/* If an existing database connection was provided, use it. */
if (isset($conf['db'])) {
$this->_db = &$conf['db'];
$this->_existingConnection = true;
$this->_opened = true;
} elseif (isset($conf['singleton'])) {
$this->_db = &MDB2::singleton($conf['singleton'], $this->_options);
$this->_existingConnection = true;
$this->_opened = true;
} else {
$this->_dsn = $conf['dsn'];
}
}

+ Here is the call graph for this function:

Log_mdb2::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. public

Reimplemented from Log.

Definition at line 161 of file mdb2.php.

References Log\$_opened, _prepareStatement(), MDB2\connect(), and PEAR\isError().

Referenced by log().

{
if (!$this->_opened) {
/* Use the DSN and options to create a database connection. */
$this->_db = &MDB2::connect($this->_dsn, $this->_options);
if (PEAR::isError($this->_db)) {
return false;
}
/* Create a prepared statement for repeated use in log(). */
if (!$this->_prepareStatement()) {
return false;
}
/* We now consider out connection open. */
$this->_opened = true;
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Log_mdb2::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.

public

Since
Log 1.8.5

Reimplemented from Log.

Definition at line 217 of file mdb2.php.

Referenced by Log_mdb2().

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

+ Here is the caller graph for this function:

Field Documentation

Log_mdb2::$_db = null

Definition at line 55 of file mdb2.php.

Log_mdb2::$_dsn = ''

Definition at line 41 of file mdb2.php.

Log_mdb2::$_existingConnection = false

Definition at line 69 of file mdb2.php.

Log_mdb2::$_identLimit = 16

Definition at line 91 of file mdb2.php.

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

Definition at line 48 of file mdb2.php.

Log_mdb2::$_sequence = 'log_id'

Definition at line 83 of file mdb2.php.

Log_mdb2::$_statement = null

Definition at line 62 of file mdb2.php.

Log_mdb2::$_table = 'log_table'

Definition at line 76 of file mdb2.php.

Log_mdb2::$_types
Initial value:
array(
'id' => 'integer',
'logtime' => 'timestamp',
'ident' => 'text',
'priority' => 'text',
'message' => 'clob'
)

Definition at line 98 of file mdb2.php.


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