forked from devsam/core
에러 로그 강화
This commit is contained in:
+14
-2
@@ -88,19 +88,28 @@ function getExceptionTraceAsString($exception) {
|
||||
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');
|
||||
$date = date("Ymd_His");
|
||||
|
||||
$errpath = str_replace(ROOT, '{ROOT}', $errpath);
|
||||
$trace = array_map(function(string $text){
|
||||
return str_replace(ROOT, '{ROOT}', $text);
|
||||
}, $trace);
|
||||
|
||||
$owner = Util::get_client_ip();
|
||||
$session = Session::getInstance();
|
||||
if($session->isLoggedIn(true)){
|
||||
$owner .= '('.$session->getUserID().','.$session->userName.')';
|
||||
}
|
||||
|
||||
$fdb->insert('err_log', [
|
||||
'date'=>$date,
|
||||
'err'=>$err,
|
||||
'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(
|
||||
getFriendlyErrorType($errno),
|
||||
$errstr,
|
||||
$errfile.':'.$errline,
|
||||
getExceptionTraceAsString($e)
|
||||
);
|
||||
}
|
||||
@@ -123,9 +133,11 @@ set_error_handler("\sammo\logErrorByCustomHandler");
|
||||
|
||||
|
||||
function logExceptionByCustomHandler(\Throwable $e){
|
||||
|
||||
logError(
|
||||
get_class($e),
|
||||
$e->getMessage(),
|
||||
$e->getFile().':'.$e->getLine(),
|
||||
getExceptionTraceAsString($e)
|
||||
);
|
||||
|
||||
|
||||
@@ -3,7 +3,9 @@ CREATE TABLE IF NOT EXISTS `err_log` (
|
||||
`date` TEXT NOT NULL,
|
||||
`err` 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` (
|
||||
`date` DESC
|
||||
|
||||
+2
-1
@@ -33,7 +33,8 @@ function Error($message='', $url="")
|
||||
if (!$url) {
|
||||
$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');
|
||||
|
||||
|
||||
+7
-1
@@ -29,7 +29,9 @@ $err_logs = $fdb->select('err_log', [
|
||||
'date',
|
||||
'err',
|
||||
'errstr',
|
||||
'trace'
|
||||
'errpath',
|
||||
'trace',
|
||||
'webuser'
|
||||
], [
|
||||
'ORDER'=>['id'=>'DESC'],
|
||||
'LIMIT'=>100
|
||||
@@ -61,9 +63,13 @@ $err_logs = $fdb->select('err_log', [
|
||||
<div class="card-body">
|
||||
<div class="card-title"><?=htmlspecialchars($err['errstr'])?></div>
|
||||
<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): ?>
|
||||
<li class="list-group-item"><?=htmlspecialchars($trace)?></li>
|
||||
<?php endforeach; ?>
|
||||
<li class="list-group-item"><?=htmlspecialchars($err['webuser'])?></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user