err_log 강화

This commit is contained in:
2019-04-21 22:15:41 +09:00
parent 0e50216cee
commit 3536d5c413
4 changed files with 25 additions and 5 deletions
+14 -2
View File
@@ -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 -1
View File
@@ -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
+1 -1
View File
@@ -34,7 +34,7 @@ function Error($message='', $url="")
$url = $_SERVER['REQUEST_URI'];
}
$e = new \Exception();
logError("aux_err", $message, getExceptionTraceAsString($e));
logError("aux_err", $message, '', getExceptionTraceAsString($e));
$templates = new \League\Plates\Engine(__dir__.'/templates');
+7 -1
View File
@@ -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>