errorhandler dbwriter mysql compatible and

This commit is contained in:
Ulf Gebhardt 2013-07-17 22:10:08 +02:00
parent 58e9e0c443
commit 219f8aa535
3 changed files with 22 additions and 11 deletions

View File

@ -7,16 +7,25 @@ namespace SYSTEM\LOG;
abstract class error_handler_dbwriter extends \SYSTEM\LOG\error_handler {
public static function CALL(\Exception $E, $errno, $thrown){
try{
$con = new \SYSTEM\DB\Connection(static::getDBInfo());
$con->prepare( 'sysLogStmt', 'INSERT INTO system.sys_log '.
'(class, message, code, file, line, trace, ip, querytime) '.
'VALUES ($1, $2, $3, $4, $5, $6, $7, $8);',
array( get_class($E), $E->getMessage(), $E->getCode(), $E->getFile(), $E->getLine(), $E->getTraceAsString(),
getenv('REMOTE_ADDR'),round(microtime(true) - \SYSTEM\time::getStartTime(),5)));
if(\SYSTEM\system::isSystemDbInfoPG()){
$con = new \SYSTEM\DB\Connection(\SYSTEM\system::getSystemDBInfo());
$con->prepare( 'sysLogStmt', 'INSERT INTO system.sys_log '.
'(class, message, code, file, line, trace, ip, querytime) '.
'VALUES ($1, $2, $3, $4, $5, $6, $7, $8);',
array( get_class($E), $E->getMessage(), $E->getCode(), $E->getFile(), $E->getLine(), $E->getTraceAsString(),
getenv('REMOTE_ADDR'),round(microtime(true) - \SYSTEM\time::getStartTime(),5)));
} else {
$con = new \SYSTEM\DB\Connection(\SYSTEM\system::getSystemDBInfo());
$con->prepare( 'sysLogStmt', 'INSERT INTO system_log '.
'(class, message, code, file, line, trace, ip, querytime) '.
'VALUES (?, ?, ?, ?, ?, ?, ?, ?);',
array( get_class($E), $E->getMessage(), $E->getCode(), $E->getFile(), $E->getLine(), $E->getTraceAsString(),
getenv('REMOTE_ADDR'),round(microtime(true) - \SYSTEM\time::getStartTime(),5)));
}
} catch (\Exception $E){} //Error -> Ignore
return false; //We just log and do not handle the error!
}
abstract protected static function getDBInfo();
}
public static function MASK(){
return \SYSTEM\CONFIG\config::get(\SYSTEM\CONFIG\config_ids::SYS_CONFIG_ERRORREPORTING);}
}

View File

@ -0,0 +1,2 @@
<?php
\SYSTEM\LOG\LOG::getInstance()->registerHandler('\SYSTEM\LOG\error_handler_dbwriter');

View File

@ -27,14 +27,14 @@ class saimod_sys_log extends \SYSTEM\SAI\SaiModule {
array('%'.$filter.'%'));
} else {
$res = $con->prepare( 'selectSysLogFilter',
'SELECT * FROM system_sys_log WHERE class ILIKE $1 ORDER BY time DESC LIMIT 100;',
'SELECT * FROM system_log WHERE class LIKE ? ORDER BY time DESC LIMIT 100;',
array('%'.$filter.'%'));
}
} else {
if(\SYSTEM\system::isSystemDbInfoPG()){
$res = $con->query('SELECT * FROM system.sys_log ORDER BY time DESC LIMIT 100;');
} else {
$res = $con->query('SELECT * FROM system_sys_log ORDER BY time DESC LIMIT 100;');
$res = $con->query('SELECT * FROM system_log ORDER BY time DESC LIMIT 100;');
}
}