more log fixes, sai log sql fixes, dbd sql

This commit is contained in:
Ulf Gebhardt 2013-12-23 04:26:00 +01:00
parent 628a93f30a
commit a9102b3663
13 changed files with 152 additions and 65 deletions

View File

@ -0,0 +1,30 @@
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (0, 42, 0, -1, NULL, 'sai_mod', NULL);
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (1, 42, 1, 0, NULL, 'js', NULL);
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (2, 42, 1, 0, NULL, 'css', NULL);
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (3, 42, 0, 0, NULL, 'action', NULL);
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (10, 42, 2, 3, 'login', 'username', 'ALL');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (11, 42, 2, 3, 'login', 'password_sha', 'ALL');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (12, 42, 2, 3, 'login', 'password_md5', 'ALL');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (20, 42, 2, 3, 'register', 'username', 'ALL');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (21, 42, 2, 3, 'register', 'password', 'ALL');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (30, 42, 2, 3, 'edit', 'id', 'ALL');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (23, 42, 2, 3, 'register', 'email', 'ALL');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (24, 42, 3, 3, 'register', 'locale', 'ALL');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (31, 42, 2, 3, 'edit', 'lang', 'LANG');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (32, 42, 2, 3, 'edit', 'newtext', 'ALL');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (33, 42, 2, 3, 'delete', 'id', 'ALL');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (34, 42, 2, 3, 'editmode', 'entry', 'ALL');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (35, 42, 2, 3, 'add', 'id', 'ALL');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (36, 42, 2, 3, 'add', 'category', 'INT');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (40, 42, 2, 3, 'upload', 'cat', 'STRING');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (41, 42, 2, 3, 'del', 'cat', 'STRING');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (42, 42, 2, 3, 'del', 'id', 'STRING');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (43, 42, 2, 3, 'rn', 'cat', 'STRING');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (44, 42, 2, 3, 'rn', 'id', 'STRING');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (45, 42, 2, 3, 'rn', 'newid', 'STRING');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (50, 42, 3, 3, 'filter', 'filter', 'STRING');
-- INSERT INTO system.api ("ID", "group", type, "parentID", "parentValue", name, verify) VALUES (302, 42, 4, -1, NULL, '_lang', 'LANG');

View File

@ -19,3 +19,10 @@ INSERT INTO system.api ("ID", "group", type, "parentID", "parentValue", name, ve
INSERT INTO system.api ("ID", "group", type, "parentID", "parentValue", name, verify) VALUES (36, 42, 2, 3, 'add', 'category', 'INT'); INSERT INTO system.api ("ID", "group", type, "parentID", "parentValue", name, verify) VALUES (36, 42, 2, 3, 'add', 'category', 'INT');
INSERT INTO system.api ("ID", "group", type, "parentID", "parentValue", name, verify) VALUES (40, 42, 3, 3, 'filter', 'filter', 'STRING'); INSERT INTO system.api ("ID", "group", type, "parentID", "parentValue", name, verify) VALUES (40, 42, 3, 3, 'filter', 'filter', 'STRING');
INSERT INTO system.api ("ID", "group", type, "parentID", "parentValue", name, verify) VALUES (302, 42, 4, -1, NULL, '_lang', 'LANG'); INSERT INTO system.api ("ID", "group", type, "parentID", "parentValue", name, verify) VALUES (302, 42, 4, -1, NULL, '_lang', 'LANG');
-- INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (40, 42, 2, 3, 'upload', 'cat', 'STRING');
-- INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (41, 42, 2, 3, 'del', 'cat', 'STRING');
-- INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (42, 42, 2, 3, 'del', 'id', 'STRING');
-- INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (43, 42, 2, 3, 'rn', 'cat', 'STRING');
-- INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (44, 42, 2, 3, 'rn', 'id', 'STRING');
-- INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (45, 42, 2, 3, 'rn', 'newid', 'STRING');

View File

@ -6,7 +6,7 @@ namespace SYSTEM\LOG;
//And only the first ErrorHandler will be called if he returns true in CALL. //And only the first ErrorHandler will be called if he returns true in CALL.
class error_handler_dbwriter extends \SYSTEM\LOG\error_handler { class error_handler_dbwriter extends \SYSTEM\LOG\error_handler {
public static function CALL(\Exception $E, $thrown){ public static function CALL(\Exception $E, $thrown){
try{ try{
if(\property_exists(get_class($E), 'logged') && $E->logged){ if(\property_exists(get_class($E), 'logged') && $E->logged){
return false;} //alrdy logged return false;} //alrdy logged
@ -20,10 +20,13 @@ class error_handler_dbwriter extends \SYSTEM\LOG\error_handler {
} else { } else {
$con = new \SYSTEM\DB\Connection(\SYSTEM\system::getSystemDBInfo()); $con = new \SYSTEM\DB\Connection(\SYSTEM\system::getSystemDBInfo());
$con->prepare( 'sysLogStmt', 'INSERT INTO system_log '. $con->prepare( 'sysLogStmt', 'INSERT INTO system_log '.
'(class, message, code, file, line, trace, ip, querytime, time) '. '(class, message, code, file, line, trace, ip, querytime, time, server_name, server_port, request_uri, post, http_referer, http_user_agent, user, thrown) '.
'VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);', 'VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);',
array( get_class($E), $E->getMessage(), $E->getCode(), $E->getFile(), $E->getLine(), $E->getTraceAsString(), array( get_class($E), $E->getMessage(), $E->getCode(), $E->getFile(), $E->getLine(), $E->getTraceAsString(),
getenv('REMOTE_ADDR'),round(microtime(true) - \SYSTEM\time::getStartTime(),5),microtime(true))); getenv('REMOTE_ADDR'),round(microtime(true) - \SYSTEM\time::getStartTime(),5),date('Y-m-d H:i:s', microtime(true)),
$_SERVER["SERVER_NAME"],$_SERVER["SERVER_PORT"],$_SERVER['REQUEST_URI'], serialize($_POST),
array_key_exists('HTTP_REFERER', $_SERVER) ? $_SERVER['HTTP_REFERER'] : null,$_SERVER['HTTP_USER_AGENT'],
($user = \SYSTEM\SECURITY\Security::getUser()) ? $user->id : null,$thrown));
} }
if(\property_exists(get_class($E), 'logged')){ if(\property_exists(get_class($E), 'logged')){
@ -31,7 +34,5 @@ class error_handler_dbwriter extends \SYSTEM\LOG\error_handler {
} catch (\Exception $E){} //Error -> Ignore } catch (\Exception $E){} //Error -> Ignore
return false; //We just log and do not handle the error! return false; //We just log and do not handle the error!
} }
public static function MASK(){
return \SYSTEM\CONFIG\config::get(\SYSTEM\CONFIG\config_ids::SYS_CONFIG_ERRORREPORTING);}
} }

View File

@ -3,8 +3,7 @@
namespace SYSTEM\LOG; namespace SYSTEM\LOG;
class error_handler_jsonoutput extends \SYSTEM\LOG\error_handler { class error_handler_jsonoutput extends \SYSTEM\LOG\error_handler {
//Only those who die! //Only those who die!
public static function MASK(){ return \E_ALL;} //\E_ERROR | \E_USER_ERROR | \E_CORE_ERROR | \E_COMPILE_ERROR; }
public static function CALL(\Exception $E, $thrown){ public static function CALL(\Exception $E, $thrown){
if($thrown){ if($thrown){
try{ try{

View File

@ -0,0 +1,5 @@
<?php
namespace SYSTEM\LOG;
class COUNTER extends \SYSTEM\LOG\INFO{}

View File

@ -0,0 +1,4 @@
<?php
namespace SYSTEM\LOG;
class SHUTDOWN_EXCEPTION extends \SYSTEM\LOG\SYSTEM_ERROR_EXCEPTION{}

View File

@ -1,10 +1,11 @@
<?php <?php
namespace SYSTEM\LOG; namespace SYSTEM\LOG;
class ShutdownException extends \ErrorException { class SYSTEM_ERROR_EXCEPTION extends \ErrorException {
public $logged = false; public $logged = false;
public function __construct($message = "", $code = 1, $severity = 0, $filename = "", $lineno = 0, $previous = NULL){ public function __construct($message = "", $code = 1, $severity = 0, $filename = "", $lineno = 0, $previous = NULL){
parent::__construct($message, $code, $severity, $filename, $lineno, $previous); parent::__construct($message, $code, $severity, $filename, $lineno, $previous);
\SYSTEM\LOG\log::__exception_handler($this,false); \SYSTEM\LOG\log::__exception_handler($this,false);
} }
} }

View File

@ -4,8 +4,7 @@ namespace SYSTEM\LOG;
//ini_set('error_prepend_string', '{querytime: 0.0, status: false, result: { class: "FatalError",message: "'); //ini_set('error_prepend_string', '{querytime: 0.0, status: false, result: { class: "FatalError",message: "');
//ini_set('error_append_string', '", code: 1, file: "unknown", line: 0, trace: }}'); //ini_set('error_append_string', '", code: 1, file: "unknown", line: 0, trace: }}');
class log { class log {
const HANDLER_FUNC_MASK = 'MASK';
const HANDLER_FUNC_CALL = 'CALL'; const HANDLER_FUNC_CALL = 'CALL';
private static $handlers = array(); private static $handlers = array();
@ -13,7 +12,6 @@ class log {
//$handler = string with classname //$handler = string with classname
public static function registerHandler($handler){ public static function registerHandler($handler){
if( !class_exists($handler) || if( !class_exists($handler) ||
!\method_exists($handler,self::HANDLER_FUNC_MASK) ||
!\method_exists($handler,self::HANDLER_FUNC_CALL)){ !\method_exists($handler,self::HANDLER_FUNC_CALL)){
die("You registered an invalid Errorhandler!");} die("You registered an invalid Errorhandler!");}
self::$handlers[] = $handler; self::$handlers[] = $handler;
@ -25,23 +23,21 @@ class log {
} }
private static function call_handlers(\Exception $E, $thrown = true){ private static function call_handlers(\Exception $E, $thrown = true){
foreach(self::$handlers as $handler){ foreach(self::$handlers as $handler){
if( ((\call_user_func(array($handler,self::HANDLER_FUNC_MASK)) & $E->getCode())) && if( \call_user_func_array(array($handler,self::HANDLER_FUNC_CALL),array($E, $thrown))){
\call_user_func_array(array($handler,self::HANDLER_FUNC_CALL),array($E, $thrown))){ return true;}}
return true;} return false;
}
return false;
} }
public static function __exception_handler(\Exception $E, $thrown = true){ public static function __exception_handler(\Exception $E, $thrown = true){
return self::call_handlers($E, $thrown) && $thrown;} return self::call_handlers($E, $thrown) && $thrown;}
public static function __error_handler($code, $message, $file, $line, $thrown = true){ public static function __error_handler($code, $message, $file, $line, $thrown = true){
return self::call_handlers(new \SYSTEM\LOG\ErrorException($message, 1, $code, $file, $line) ,$thrown);} return self::call_handlers(new \SYSTEM\LOG\ERROR_EXCEPTION($message, 1, $code, $file, $line) ,$thrown);}
public static function __shutdown_handler($thrown = true) { public static function __shutdown_handler($thrown = true) {
if( ($error = error_get_last()) !== NULL && !$error['type'] === E_DEPRECATED) { //http://www.dreamincode.net/forums/topic/284506-having-trouble-supressing-magic-quotes-gpc-fatal-errors/ if( ($error = error_get_last()) !== NULL && !$error['type'] === E_DEPRECATED) { //http://www.dreamincode.net/forums/topic/284506-having-trouble-supressing-magic-quotes-gpc-fatal-errors/
return self::call_handlers(new \SYSTEM\LOG\ShutdownException($error["message"], 1, $error["type"],$error["file"],$error["line"]) ,$thrown);} return self::call_handlers(new \SYSTEM\LOG\SHUTDOWN_EXCEPTION($error["message"], 1, $error["type"],$error["file"],$error["line"]) ,$thrown);}
} }
public static function __fatal_error_handler($bufferContent, $thrown = true){ public static function __fatal_error_handler($bufferContent, $thrown = true){

Binary file not shown.

After

Width:  |  Height:  |  Size: 723 B

View File

@ -33,6 +33,7 @@ function init__SYSTEM_SAI_saimod_sys_log() {
function drawVisualization() { function drawVisualization() {
$('img#loader').show(); $('img#loader').show();
console.log(SAI_ENDPOINT+'sai_mod=.SYSTEM.SAI.saimod_sys_log&action=visualization');
$.getJSON(SAI_ENDPOINT+'sai_mod=.SYSTEM.SAI.saimod_sys_log&action=visualization',function(json){ $.getJSON(SAI_ENDPOINT+'sai_mod=.SYSTEM.SAI.saimod_sys_log&action=visualization',function(json){
if(json.status != true){ if(json.status != true){
$('img#loader').hide(); $('img#loader').hide();
@ -145,5 +146,6 @@ function do_filter(filter){
$('#visualization').hide(); $('#visualization').hide();
$(this).parents().children().removeClass('active'); $(this).parents().children().removeClass('active');
$(this).addClass('active'); $(this).addClass('active');
console.log(SAI_ENDPOINT+'sai_mod=.SYSTEM.SAI.saimod_sys_log&action=filter&filter='+filter);
$('#table-wrapper').load(SAI_ENDPOINT+'sai_mod=.SYSTEM.SAI.saimod_sys_log&action=filter&filter='+filter,function(){$('#table-wrapper').show(); $('img#loader').hide();}); $('#table-wrapper').load(SAI_ENDPOINT+'sai_mod=.SYSTEM.SAI.saimod_sys_log&action=filter&filter='+filter,function(){$('#table-wrapper').show(); $('img#loader').hide();});
} }

View File

@ -14,36 +14,67 @@ class saimod_sys_log extends \SYSTEM\SAI\SaiModule {
return false; return false;
} }
public static function sai_mod__SYSTEM_SAI_saimod_sys_log_action_visualization(){ public static function sai_mod__SYSTEM_SAI_saimod_sys_log_action_visualization(){
$con = new \SYSTEM\DB\Connection(\SYSTEM\system::getSystemDBInfo()); $con = new \SYSTEM\DB\Connection(\SYSTEM\system::getSystemDBInfo());
$res = $con->query('SELECT time::date as day, if(\SYSTEM\system::isSystemDbInfoPG()){
min(time) as time_min, max(time) as time_max, $res = $con->query('SELECT time::date as day,
count(*) as count, min(time) as time_min, max(time) as time_max,
avg(querytime) as querytime_avg, count(*) as count,
max(querytime) as querytime_max, avg(querytime) as querytime_avg,
min(querytime) as querytime_min, max(querytime) as querytime_max,
count(distinct file) as file_unique, min(querytime) as querytime_min,
count(distinct ip) as ip_unique, count(distinct file) as file_unique,
count(distinct message) as text_unique, count(distinct ip) as ip_unique,
count(distinct class) as class_unique, count(distinct message) as text_unique,
sum(case when class = \'INFO\' then 1 else 0 end) class_INFO, count(distinct class) as class_unique,
sum(case when class = \'DEPRECATED\' then 1 else 0 end) class_DEPRECATED, sum(case when class = \'INFO\' then 1 else 0 end) class_INFO,
sum(case when class = \'WARNING\' then 1 else 0 end) class_WARNING, sum(case when class = \'DEPRECATED\' then 1 else 0 end) class_DEPRECATED,
sum(case when class = \'ERROR\' then 1 else 0 end) class_ERROR, sum(case when class = \'WARNING\' then 1 else 0 end) class_WARNING,
sum(case when class = \'AppError\' then 1 else 0 end) class_AppError, sum(case when class = \'ERROR\' then 1 else 0 end) class_ERROR,
sum(case when class = \'SYSTEM\LOG\INFO\' then 1 else 0 end) class_SYSTEM_LOG_INFO, sum(case when class = \'AppError\' then 1 else 0 end) class_AppError,
sum(case when class = \'SYSTEM\LOG\DEPRECATED\' then 1 else 0 end) class_SYSTEM_LOG_DEPRECATED, sum(case when class = \'SYSTEM\LOG\INFO\' then 1 else 0 end) class_SYSTEM_LOG_INFO,
sum(case when class = \'SYSTEM\LOG\WARNING\' then 1 else 0 end) class_SYSTEM_LOG_WARNING, sum(case when class = \'SYSTEM\LOG\DEPRECATED\' then 1 else 0 end) class_SYSTEM_LOG_DEPRECATED,
sum(case when class = \'SYSTEM\LOG\ERROR\' then 1 else 0 end) class_SYSTEM_LOG_ERROR, sum(case when class = \'SYSTEM\LOG\WARNING\' then 1 else 0 end) class_SYSTEM_LOG_WARNING,
sum(case when class = \'SYSTEM\LOG\ErrorException\' then 1 else 0 end) class_SYSTEM_LOG_ErrorException, sum(case when class = \'SYSTEM\LOG\ERROR\' then 1 else 0 end) class_SYSTEM_LOG_ERROR,
sum(case when class = \'SYSTEM\LOG\ShutdownException\' then 1 else 0 end) class_SYSTEM_LOG_ShutdownException, sum(case when class = \'SYSTEM\LOG\ErrorException\' then 1 else 0 end) class_SYSTEM_LOG_ErrorException,
sum(case when class = \'Exception\' then 1 else 0 end) class_Exception, sum(case when class = \'SYSTEM\LOG\ShutdownException\' then 1 else 0 end) class_SYSTEM_LOG_ShutdownException,
sum(case when class = \'RuntimeException\' then 1 else 0 end) class_RuntimeException, sum(case when class = \'Exception\' then 1 else 0 end) class_Exception,
sum(case when class = \'ErrorException\' then 1 else 0 end) class_ErrorException sum(case when class = \'RuntimeException\' then 1 else 0 end) class_RuntimeException,
from system.sys_log sum(case when class = \'ErrorException\' then 1 else 0 end) class_ErrorException
group by day from system.sys_log
order by day desc group by day
limit 365;'); order by day desc
limit 365;');
} else {
$res = $con->query('SELECT DATE(time) as day,
min(time) as time_min, max(time) as time_max,
count(*) as count,
avg(querytime) as querytime_avg,
max(querytime) as querytime_max,
min(querytime) as querytime_min,
count(distinct file) as file_unique,
count(distinct ip) as ip_unique,
count(distinct message) as text_unique,
count(distinct class) as class_unique,
sum(case when class = \'INFO\' then 1 else 0 end) class_INFO,
sum(case when class = \'DEPRECATED\' then 1 else 0 end) class_DEPRECATED,
sum(case when class = \'WARNING\' then 1 else 0 end) class_WARNING,
sum(case when class = \'ERROR\' then 1 else 0 end) class_ERROR,
sum(case when class = \'AppError\' then 1 else 0 end) class_AppError,
sum(case when class = \'SYSTEM\LOG\INFO\' then 1 else 0 end) class_SYSTEM_LOG_INFO,
sum(case when class = \'SYSTEM\LOG\DEPRECATED\' then 1 else 0 end) class_SYSTEM_LOG_DEPRECATED,
sum(case when class = \'SYSTEM\LOG\WARNING\' then 1 else 0 end) class_SYSTEM_LOG_WARNING,
sum(case when class = \'SYSTEM\LOG\ERROR\' then 1 else 0 end) class_SYSTEM_LOG_ERROR,
sum(case when class = \'SYSTEM\LOG\ErrorException\' then 1 else 0 end) class_SYSTEM_LOG_ErrorException,
sum(case when class = \'SYSTEM\LOG\ShutdownException\' then 1 else 0 end) class_SYSTEM_LOG_ShutdownException,
sum(case when class = \'Exception\' then 1 else 0 end) class_Exception,
sum(case when class = \'RuntimeException\' then 1 else 0 end) class_RuntimeException,
sum(case when class = \'ErrorException\' then 1 else 0 end) class_ErrorException
from system_log
group by day
order by day desc
limit 365;');
}
$result = array(); $result = array();
while($row = $res->next()){ while($row = $res->next()){
$result[] = $row;} $result[] = $row;}
@ -61,28 +92,34 @@ class saimod_sys_log extends \SYSTEM\SAI\SaiModule {
array($filter)); array($filter));
} else { } else {
$res = $con->prepare( 'selectSysLogFilter', $res = $con->prepare( 'selectSysLogFilter',
'SELECT * FROM system_log WHERE class LIKE ? ORDER BY time DESC LIMIT 100;', 'SELECT * FROM system_log LEFT JOIN system_user ON system_log.user = system_user.id WHERE class LIKE ? ORDER BY time DESC LIMIT 100;',
array($filter)); array(mysql_escape_string($filter)));
} }
} else { } else {
if(\SYSTEM\system::isSystemDbInfoPG()){ if(\SYSTEM\system::isSystemDbInfoPG()){
$res = $con->query('SELECT * FROM system.sys_log ORDER BY time DESC LIMIT 100;'); $res = $con->query('SELECT * FROM system.sys_log ORDER BY time DESC LIMIT 100;');
} else { } else {
$res = $con->query('SELECT * FROM system_log ORDER BY time DESC LIMIT 100;'); $res = $con->query('SELECT * FROM system_log LEFT JOIN system_user ON system_log.user = system_user.id ORDER BY time DESC LIMIT 100;');
} }
} }
$now = microtime(true); $now = microtime(true);
$result = '<table class="table table-hover table-condensed">'. $result = '<table class="table table-hover table-condensed">'.
'<tr>'.'<th>'.'time ago'.'</th>'.'<th>'.'time'.'</th>'.'<th>'.'class'.'</th>'.'<th>'.'message'.'</th>'.'<th>'.'code'.'</th>'.'<th>'.'file'.'</th>'.'<th>'.'line'.'</th>'.'<th>'.'ip'.'</th>'.'<th>'.'querytime'.'</tr>'; '<tr>'.'<th>'.'time ago'.'</th>'.'<th>'.'class'.'</th>'.'<th>'.'message'.'</th>'.'<th>'.'file'.'</th>'.'<th>'.'line'.'</th>'.'<th>'.'ip'.'</th>'.'<th>'.'url'.'</th>'.'<th>'.'user'.'</th>'.'<th>'.'querytime'.'</tr>';
while($r = $res->next()){ while($r = $res->next()){
//TODO make time conversion on database //print_r($r);
if(\SYSTEM\system::isSystemDbInfoPG()){ $result .= '<tr class="sai_log_error '.self::tablerow_class($r['class']).'" error="'.$r['ID'].'">'.
$result .= '<tr class="'.self::tablerow_class($r['class']).'">'.'<td>'.self::time_elapsed_string(strtotime($r['time'])).'</td>'.'<td>'.$r['time'].'</td>'.'<td>'.$r['class'].'</td>'.'<td style="word-break: break-all">'.substr($r['message'],0,255).'</td>'.'<td>'.$r['code'].'</td>'.'<td style="word-break: break-all">'.$r['file'].'</td>'.'<td>'.$r['line'].'</td>'.'<td>'.$r['ip'].'</td>'.'<td>'.$r['querytime'].'</td>'.'</tr>'; '<td>'.self::time_elapsed_string(strtotime($r['time'])).'</td>'.
} else { '<td>'.$r['class'].'</td>'.
$result .= '<tr class="'.self::tablerow_class($r['class']).'">'.'<td>'.self::time_elapsed_string($r['time']).'</td>'.'<td>'.$r['time'].'</td>'.'<td>'.$r['class'].'</td>'.'<td style="word-break: break-all;">'.substr($r['message'],0,255).'</td>'.'<td>'.$r['code'].'</td>'.'<td>'.$r['file'].'</td>'.'<td>'.$r['line'].'</td>'.'<td>'.$r['ip'].'</td>'.'<td>'.$r['querytime'].'</td>'.'</tr>'; '<td style="word-break: break-all;">'.substr($r['message'],0,255).'</td>'.
} '<td style="word-break: break-all;">'.$r['file'].'</td>'.
'<td>'.$r['line'].'</td>'.
'<td>'.$r['ip'].'</td>'.
'<td style="word-break: break-all;">'.$r['server_name'].':'.$r['server_port'].$r['request_uri'].'</td>'.
'<td>'.$r['username'].'</td>'.
'<td>'.$r['querytime'].'</td>'.
'</tr>';
} }
$result .= '</table>'; $result .= '</table>';
@ -112,7 +149,11 @@ class saimod_sys_log extends \SYSTEM\SAI\SaiModule {
private static function generate_error_filters(){ private static function generate_error_filters(){
$con = new \SYSTEM\DB\Connection(\SYSTEM\system::getSystemDBInfo()); $con = new \SYSTEM\DB\Connection(\SYSTEM\system::getSystemDBInfo());
$res = $con->query("SELECT class FROM system.sys_log GROUP BY class ORDER BY class;"); if(\SYSTEM\system::isSystemDbInfoPG()){
$res = $con->query("SELECT class FROM system.sys_log GROUP BY class ORDER BY class;");
}else{
$res = $con->query("SELECT class FROM system_log GROUP BY class ORDER BY class;");
}
$result = ""; $result = "";
$i = 1; $i = 1;
@ -122,9 +163,10 @@ class saimod_sys_log extends \SYSTEM\SAI\SaiModule {
return $result; return $result;
} }
public static function sai_mod__SYSTEM_SAI_saimod_sys_log(){ public static function sai_mod__SYSTEM_SAI_saimod_sys_log(){
$vars = array(); $vars = array();
$vars['error_filter'] = self::generate_error_filters(); $vars['error_filter'] = self::generate_error_filters();
$vars['PICPATH'] = \SYSTEM\WEBPATH(new \SYSTEM\PSAI(), 'modules/saimod_sys_log/img/');
return \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new \SYSTEM\PSAI(),'modules/saimod_sys_log/saimod_sys_log.tpl'), $vars); return \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new \SYSTEM\PSAI(),'modules/saimod_sys_log/saimod_sys_log.tpl'), $vars);
} }

View File

@ -14,7 +14,7 @@
</div> </div>
<button id="refresh_error_table" class="btn" style="height: 32px; font-size: 13px; float: left">Refresh</button> <button id="refresh_error_table" class="btn" style="height: 32px; font-size: 13px; float: left">Refresh</button>
<img id="loader" src="dasense/page/default_developer/img/ajax-loader.gif" style="margin-left: 10px; display: none; float: left"/> <img id="loader" src="${PICPATH}ajax-loader.gif" style="margin-left: 10px; display: none; float: left"/>
<div id="filter-error" class="btn-group" style="left: 60px; float: left;"> <div id="filter-error" class="btn-group" style="left: 60px; float: left;">
<button class="btn active" href="#" filter="">All</button> <button class="btn active" href="#" filter="">All</button>
${error_filter} ${error_filter}