41 lines
1.5 KiB
PHP
41 lines
1.5 KiB
PHP
<?php
|
|
declare (strict_types = 1);
|
|
|
|
namespace app\handle\controller;
|
|
|
|
use think\facade\Request;
|
|
use think\response\Json;
|
|
|
|
class Log
|
|
{
|
|
public function report(): Json
|
|
{
|
|
if (!Request::instance()->isPost()) return json(['status' => 0]);
|
|
$data = Request::instance()->post();
|
|
if (empty($data)) {
|
|
$raw = Request::instance()->getContent();
|
|
$data = json_decode($raw, true) ?: [];
|
|
}
|
|
if (empty($data)) {
|
|
$raw2 = file_get_contents('php://input');
|
|
$data = json_decode($raw2, true) ?: [];
|
|
}
|
|
try {
|
|
\app\utils\Logger::error(\app\utils\Logger::CAT_FRONTEND, $data['message'] ?? 'unknown', [
|
|
'source' => $data['source'] ?? 'unknown',
|
|
'type' => $data['type'] ?? 'error',
|
|
'stack' => isset($data['stack']) ? substr($data['stack'], 0, 2000) : '',
|
|
'file' => $data['file'] ?? '',
|
|
'url' => $data['url'] ?? '',
|
|
'line' => $data['line'] ?? '',
|
|
'col' => $data['col'] ?? '',
|
|
'ua' => Request::instance()->header('user-agent', ''),
|
|
'ip' => Request::instance()->ip(),
|
|
]);
|
|
return json(['status' => 1, 'path' => runtime_path(), 'data_keys' => array_keys($data)]);
|
|
} catch (\Throwable $e) {
|
|
return json(['status' => 0, 'error' => $e->getMessage(), 'path' => runtime_path()]);
|
|
}
|
|
}
|
|
}
|