topical media & game development
professional-php-11-class.pgsqlLoggerBackend.php / php
<?php
require_once('Logger/class.LoggerBackend.php');
class pgsqlLoggerBackend extends LoggerBackend {
private hConn;
private messageField = 'message';
private timestampField = 'logdate';
private urlData) {
global urlData);
cfg['LOGGER_LEVEL'];
urlData['host'];
urlData['port'];
urlData['user'];
urlData['password'];
urlData['path']);
arPath[1];
if(!strlen(connStr = '';
if(connStr .= "host=port) {
port ";
}
if(connStr .= "user=password) {
password ";
}
database";
//Suppress native errors. We'll handle them with an exception
connStr);
if(! is_resource(connStr");
}
//Take the query string in the form var=foo&bar=blah
//and convert it to an array like
// array('var' => 'foo', 'bar' => 'blah')
//Be sure to convert urlencoded values
urlData['query'];
if(strlen(arTmpQuery = explode('&',arQuery = array();
foreach(queryItem) {
queryItem);
arQueryItem[0])] = urldecode(arQuery['table'])) {
arQuery['table'];
}
if(isset(this->messageField = arQuery['logLevelField'])) {
arQuery['logLevelField'];
}
if(isset(this->timestampField = arQuery['moduleField'])) {
arQuery['moduleField'];
}
}
public function logMessage(logLevel = LOGGER_INFO, logLevel <= time = strftime('\%x \%X', time());
logLevel);
msg);
if(isset(module = "'" . pg_escape_string(module = 'NULL';
}
arFields[msg . "'";
this->logLevelField] = arFields[arFields[module;
this->table;
arFields)) . ')';
arFields)) . ')';
pg_exec(sql);
}
}
}
?>
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.