에러 로그 강화
This commit is contained in:
+14
-2
@@ -88,19 +88,28 @@ function getExceptionTraceAsString($exception) {
|
|||||||
return $rtn;
|
return $rtn;
|
||||||
}
|
}
|
||||||
|
|
||||||
function logError(string $err, string $errstr, array $trace){
|
function logError(string $err, string $errstr, string $errpath, array $trace){
|
||||||
$fdb = FileDB::db(ROOT.'/d_log/err_log.sqlite3', ROOT.'/f_install/sql/err_log.sql');
|
$fdb = FileDB::db(ROOT.'/d_log/err_log.sqlite3', ROOT.'/f_install/sql/err_log.sql');
|
||||||
$date = date("Ymd_His");
|
$date = date("Ymd_His");
|
||||||
|
|
||||||
|
$errpath = str_replace(ROOT, '{ROOT}', $errpath);
|
||||||
$trace = array_map(function(string $text){
|
$trace = array_map(function(string $text){
|
||||||
return str_replace(ROOT, '{ROOT}', $text);
|
return str_replace(ROOT, '{ROOT}', $text);
|
||||||
}, $trace);
|
}, $trace);
|
||||||
|
|
||||||
|
$owner = Util::get_client_ip();
|
||||||
|
$session = Session::getInstance();
|
||||||
|
if($session->isLoggedIn(true)){
|
||||||
|
$owner .= '('.$session->getUserID().','.$session->userName.')';
|
||||||
|
}
|
||||||
|
|
||||||
$fdb->insert('err_log', [
|
$fdb->insert('err_log', [
|
||||||
'date'=>$date,
|
'date'=>$date,
|
||||||
'err'=>$err,
|
'err'=>$err,
|
||||||
'errstr'=>$errstr,
|
'errstr'=>$errstr,
|
||||||
'trace'=>Json::encode($trace)
|
'errpath'=>$errpath,
|
||||||
|
'trace'=>Json::encode($trace),
|
||||||
|
'webuser'=>$owner
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,6 +125,7 @@ function logErrorByCustomHandler(int $errno, string $errstr, string $errfile, in
|
|||||||
logError(
|
logError(
|
||||||
getFriendlyErrorType($errno),
|
getFriendlyErrorType($errno),
|
||||||
$errstr,
|
$errstr,
|
||||||
|
$errfile.':'.$errline,
|
||||||
getExceptionTraceAsString($e)
|
getExceptionTraceAsString($e)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -123,9 +133,11 @@ set_error_handler("\sammo\logErrorByCustomHandler");
|
|||||||
|
|
||||||
|
|
||||||
function logExceptionByCustomHandler(\Throwable $e){
|
function logExceptionByCustomHandler(\Throwable $e){
|
||||||
|
|
||||||
logError(
|
logError(
|
||||||
get_class($e),
|
get_class($e),
|
||||||
$e->getMessage(),
|
$e->getMessage(),
|
||||||
|
$e->getFile().':'.$e->getLine(),
|
||||||
getExceptionTraceAsString($e)
|
getExceptionTraceAsString($e)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,9 @@ CREATE TABLE IF NOT EXISTS `err_log` (
|
|||||||
`date` TEXT NOT NULL,
|
`date` TEXT NOT NULL,
|
||||||
`err` TEXT NOT NULL,
|
`err` TEXT NOT NULL,
|
||||||
`errstr` TEXT NOT NULL,
|
`errstr` TEXT NOT NULL,
|
||||||
`trace` TEXT NOT NULL
|
`errpath` TEXT NOT NULL,
|
||||||
|
`trace` TEXT NOT NULL,
|
||||||
|
`webuser` TEXT NULL
|
||||||
);
|
);
|
||||||
CREATE INDEX IF NOT EXISTS `date` ON `err_log` (
|
CREATE INDEX IF NOT EXISTS `date` ON `err_log` (
|
||||||
`date` DESC
|
`date` DESC
|
||||||
|
|||||||
+2
-1
@@ -33,7 +33,8 @@ function Error($message='', $url="")
|
|||||||
if (!$url) {
|
if (!$url) {
|
||||||
$url = $_SERVER['REQUEST_URI'];
|
$url = $_SERVER['REQUEST_URI'];
|
||||||
}
|
}
|
||||||
file_put_contents(__dir__."/logs/".UniqueConst::$serverID."/_db_bug.txt", "{\"url\":\"$url\",\"msg\":\"$message\"}\n", FILE_APPEND);
|
$e = new \Exception();
|
||||||
|
logError("aux_err", $message, '', getExceptionTraceAsString($e));
|
||||||
|
|
||||||
$templates = new \League\Plates\Engine(__dir__.'/templates');
|
$templates = new \League\Plates\Engine(__dir__.'/templates');
|
||||||
|
|
||||||
|
|||||||
+7
-1
@@ -29,7 +29,9 @@ $err_logs = $fdb->select('err_log', [
|
|||||||
'date',
|
'date',
|
||||||
'err',
|
'err',
|
||||||
'errstr',
|
'errstr',
|
||||||
'trace'
|
'errpath',
|
||||||
|
'trace',
|
||||||
|
'webuser'
|
||||||
], [
|
], [
|
||||||
'ORDER'=>['id'=>'DESC'],
|
'ORDER'=>['id'=>'DESC'],
|
||||||
'LIMIT'=>100
|
'LIMIT'=>100
|
||||||
@@ -61,9 +63,13 @@ $err_logs = $fdb->select('err_log', [
|
|||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<div class="card-title"><?=htmlspecialchars($err['errstr'])?></div>
|
<div class="card-title"><?=htmlspecialchars($err['errstr'])?></div>
|
||||||
<ul class="list-group list-group-flush">
|
<ul class="list-group list-group-flush">
|
||||||
|
<?php if($err['errpath']): ?>
|
||||||
|
<li class="list-group-item"><?=htmlspecialchars($err['errpath'])?></li>
|
||||||
|
<?php endif; ?>
|
||||||
<?php foreach(Json::decode($err['trace']) as $trace): ?>
|
<?php foreach(Json::decode($err['trace']) as $trace): ?>
|
||||||
<li class="list-group-item"><?=htmlspecialchars($trace)?></li>
|
<li class="list-group-item"><?=htmlspecialchars($trace)?></li>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
|
<li class="list-group-item"><?=htmlspecialchars($err['webuser'])?></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user