10require_once
'MDB2.php';
100 'logtime' =>
'timestamp',
102 'priority' =>
'text',
115 function Log_mdb2($name, $ident =
'', $conf = array(),
118 $this->_id = md5(microtime());
119 $this->_table = $name;
123 if (isset($conf[
'options']) && is_array($conf[
'options'])) {
124 $this->_options = $conf[
'options'];
128 if (!empty($conf[
'sequence'])) {
129 $this->_sequence = $conf[
'sequence'];
133 if (isset($conf[
'identLimit'])) {
134 $this->_identLimit = $conf[
'identLimit'];
141 if (isset($conf[
'db'])) {
142 $this->_db = &$conf[
'db'];
143 $this->_existingConnection =
true;
144 $this->_opened =
true;
145 } elseif (isset($conf[
'singleton'])) {
147 $this->_existingConnection =
true;
148 $this->_opened =
true;
150 $this->_dsn = $conf[
'dsn'];
163 if (!$this->_opened) {
176 $this->_opened =
true;
193 if (is_object($this->_statement)) {
194 $this->_statement->free();
195 $this->_statement =
null;
199 if ($this->_opened && !$this->_existingConnection) {
200 $this->_opened =
false;
201 return $this->_db->disconnect();
204 return ($this->_opened ===
false);
219 $this->_ident = substr($ident, 0, $this->_identLimit);
235 function log($message, $priority =
null)
238 if ($priority ===
null) {
248 if (!$this->_opened && !$this->
open()) {
262 'id' => $this->_db->nextId($this->_sequence),
264 'ident' => $this->_ident,
265 'priority' => $priority,
266 'message' => $message
271 $result = &$this->_statement->execute($values);
272 $this->_db->popExpect();
287 $this->_statement->free();
293 $result = $this->_statement->execute($values);
299 $this->
_announce(array(
'priority' => $priority,
'message' => $message));
312 $this->_db->loadModule(
'Manager',
null,
true);
313 $result = $this->_db->manager->createTable(
316 'id' => array(
'type' => $this->_types[
'id']),
317 'logtime' => array(
'type' => $this->_types[
'logtime']),
318 'ident' => array(
'type' => $this->_types[
'ident']),
319 'priority' => array(
'type' => $this->_types[
'priority']),
320 'message' => array(
'type' => $this->_types[
'message'])
327 $result = $this->_db->manager->createIndex(
330 array(
'fields' => array(
'id' =>
true),
'unique' =>
true)
349 $this->_statement = &$this->_db->prepare(
350 'INSERT INTO ' . $this->_table .
351 ' (id, logtime, ident, priority, message)' .
352 ' VALUES(:id, :logtime, :ident, :priority, :message)',
const MDB2_PREPARE_MANIP
These are just helper constants to more verbosely express parameters to prepare()
const MDB2_ERROR_NOSUCHTABLE
_prepareStatement()
Prepare the SQL insertion statement.
Log_mdb2($name, $ident='', $conf=array(), $level=PEAR_LOG_DEBUG)
Constructs a new sql logging object.
_createTable()
Create the log table in the database.
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.
UPTO($priority)
Calculate the log mask for all priorities up to the given priority.
_isMasked($priority)
Check if the given priority is included in the current level mask.
_announce($event)
Informs each registered observer instance that a new message has been logged.
_extractMessage($message)
Returns the string representation of the message data.
mdbNow()
return the current datetime
loadFile($file)
load a file (like 'Date')
& connect($dsn, $options=false)
Create a new MDB2 connection object and connect to the specified database.
& singleton($dsn=null, $options=false)
Returns a MDB2 connection with the requested DSN.
isError($data, $code=null)
Tell whether a value is a PEAR error.
The Log:: class implements both an abstraction for various logging mechanisms and the Subject end of ...