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

Public Member Functions

 Log_sqlite ($name, $ident='', &$conf, $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...
 
 log ($message, $priority=null)
 Inserts $message to the currently open database. More...
 
 _createTable ()
 Checks whether the log table exists and creates it if necessary. 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

 $_options
 
 $_db = null
 
 $_existingConnection = false
 
 $_table = 'log_table'
 
- 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 31 of file sqlite.php.

Member Function Documentation

◆ _createTable()

Log_sqlite::_createTable ( )

Checks whether the log table exists and creates it if necessary.

Returns
boolean True on success or false on failure. @access private

Definition at line 202 of file sqlite.php.

203 {
204 $q = "SELECT name FROM sqlite_master WHERE name='" . $this->_table .
205 "' AND type='table'";
206
207 $res = sqlite_query($this->_db, $q);
208
209 if (sqlite_num_rows($res) == 0) {
210 $q = 'CREATE TABLE [' . $this->_table . '] (' .
211 'id INTEGER PRIMARY KEY NOT NULL, ' .
212 'logtime NOT NULL, ' .
213 'ident CHAR(16) NOT NULL, ' .
214 'priority INT NOT NULL, ' .
215 'message)';
216
217 if (!($res = sqlite_unbuffered_query($this->_db, $q))) {
218 return false;
219 }
220 }
221
222 return true;
223 }

References $res.

Referenced by open().

+ Here is the caller graph for this function:

◆ close()

Log_sqlite::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 132 of file sqlite.php.

133 {
134 /* We never close existing connections. */
135 if ($this->_existingConnection) {
136 return false;
137 }
138
139 if ($this->_opened) {
140 $this->_opened = false;
141 sqlite_close($this->_db);
142 }
143
144 return ($this->_opened === false);
145 }

◆ log()

Log_sqlite::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 160 of file sqlite.php.

161 {
162 /* If a priority hasn't been specified, use the default value. */
163 if ($priority === null) {
164 $priority = $this->_priority;
165 }
166
167 /* Abort early if the priority is above the maximum logging level. */
168 if (!$this->_isMasked($priority)) {
169 return false;
170 }
171
172 /* If the connection isn't open and can't be opened, return failure. */
173 if (!$this->_opened && !$this->open()) {
174 return false;
175 }
176
177 // Extract the string representation of the message.
178 $message = $this->_extractMessage($message);
179
180 // Build the SQL query for this log entry insertion.
181 $q = sprintf('INSERT INTO [%s] (logtime, ident, priority, message) ' .
182 "VALUES ('%s', '%s', %d, '%s')",
183 $this->_table,
184 strftime('%Y-%m-%d %H:%M:%S', time()),
185 sqlite_escape_string($this->_ident),
186 $priority,
187 sqlite_escape_string($message));
188 if (!($res = @sqlite_unbuffered_query($this->_db, $q))) {
189 return false;
190 }
191 $this->_announce(array('priority' => $priority, 'message' => $message));
192
193 return true;
194 }
open()
Opens a connection to the database, if it has not already been opened.
Definition: sqlite.php:99
$_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, $res, Log\_announce(), Log\_extractMessage(), Log\_isMasked(), and open().

+ Here is the call graph for this function:

◆ Log_sqlite()

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

Constructs a new sql logging object.

Parameters
string$nameThe target SQL table.
string$identThe identification field.
mixed$confCan be an array of configuration options used to open a new database connection or an already opened sqlite connection.
int$levelLog messages up to and including this level. @access public

Definition at line 74 of file sqlite.php.

75 {
76 $this->_id = md5(microtime());
77 $this->_table = $name;
78 $this->_ident = $ident;
79 $this->_mask = Log::UPTO($level);
80
81 if (is_array($conf)) {
82 foreach ($conf as $k => $opt) {
83 $this->_options[$k] = $opt;
84 }
85 } else {
86 // If an existing database connection was provided, use it.
87 $this->_db =& $conf;
88 $this->_existingConnection = true;
89 }
90 }
UPTO($priority)
Calculate the log mask for all priorities up to the given priority.
Definition: Log.php:642

References Log\UPTO().

+ Here is the call graph for this function:

◆ open()

Log_sqlite::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 99 of file sqlite.php.

100 {
101 if (is_resource($this->_db)) {
102 $this->_opened = true;
103 return $this->_createTable();
104 } else {
105 /* Set the connection function based on the 'persistent' option. */
106 if (empty($this->_options['persistent'])) {
107 $connectFunction = 'sqlite_open';
108 } else {
109 $connectFunction = 'sqlite_popen';
110 }
111
112 /* Attempt to connect to the database. */
113 if ($this->_db = $connectFunction($this->_options['filename'],
114 (int)$this->_options['mode'],
115 $error)) {
116 $this->_opened = true;
117 return $this->_createTable();
118 }
119 }
120
121 return $this->_opened;
122 }
_createTable()
Checks whether the log table exists and creates it if necessary.
Definition: sqlite.php:202
$_opened
Definition: Log.php:45

References Log\$_opened, and _createTable().

Referenced by log().

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

Field Documentation

◆ $_db

Log_sqlite::$_db = null

Definition at line 46 of file sqlite.php.

◆ $_existingConnection

Log_sqlite::$_existingConnection = false

Definition at line 53 of file sqlite.php.

◆ $_options

Log_sqlite::$_options
Initial value:
= array('mode' => 0666,
'persistent' => false)

Definition at line 38 of file sqlite.php.

◆ $_table

Log_sqlite::$_table = 'log_table'

Definition at line 60 of file sqlite.php.


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