16if (!class_exists(
'DB')) {
17 require_once
'DB.php';
120 function Log_sql($name, $ident =
'', $conf = array(),
123 $this->_id = md5(microtime());
124 $this->_table = $name;
128 if (!empty($conf[
'sql'])) {
129 $this->_sql = $conf[
'sql'];
131 $this->_sql =
'INSERT INTO ' . $this->_table .
132 ' (id, logtime, ident, priority, message)' .
133 ' VALUES(?, CURRENT_TIMESTAMP, ?, ?, ?)';
137 if (isset($conf[
'options']) && is_array($conf[
'options'])) {
138 $this->_options = $conf[
'options'];
142 if (!empty($conf[
'sequence'])) {
143 $this->_sequence = $conf[
'sequence'];
147 if (isset($conf[
'identLimit'])) {
148 $this->_identLimit = $conf[
'identLimit'];
155 if (isset($conf[
'db'])) {
156 $this->_db = &$conf[
'db'];
157 $this->_existingConnection =
true;
158 $this->_opened =
true;
160 $this->_dsn = $conf[
'dsn'];
173 if (!$this->_opened) {
175 $this->_db = &DB::connect($this->_dsn, $this->_options);
176 if (DB::isError($this->_db)) {
186 $this->_opened =
true;
202 if ($this->_opened && !$this->_existingConnection) {
203 $this->_opened =
false;
204 $this->_db->freePrepared($this->_statement);
205 return $this->_db->disconnect();
208 return ($this->_opened ===
false);
223 $this->_ident = substr($ident, 0, $this->_identLimit);
239 function log($message, $priority =
null)
242 if ($priority ===
null) {
252 if (!$this->_opened && !$this->
open()) {
265 $id = $this->_db->nextId($this->_sequence);
266 $values = array($id, $this->_ident, $priority, $message);
269 $result =& $this->_db->execute($this->_statement, $values);
274 $this->
_announce(array(
'priority' => $priority,
'message' => $message));
289 $this->_statement = $this->_db->prepare($this->_sql);
292 return (DB::isError($this->_statement) ===
false);
setIdent($ident)
Sets this Log instance's identification string.
Log_sql($name, $ident='', $conf=array(), $level=PEAR_LOG_DEBUG)
Constructs a new sql logging object.
_prepareStatement()
Prepare the SQL insertion statement.
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.
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.
The Log:: class implements both an abstraction for various logging mechanisms and the Subject end of ...