Commit b0e265fd authored by 王源's avatar 王源 🎧

异常收集排除依赖包文件和运行缓存文件

parent be9d19f9
...@@ -4,6 +4,7 @@ declare(strict_types=1); ...@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Meibuyu\Micro\Amqp\Producer; namespace Meibuyu\Micro\Amqp\Producer;
use Exception;
use Hyperf\Amqp\Annotation\Producer; use Hyperf\Amqp\Annotation\Producer;
use Hyperf\Amqp\Message\ProducerMessage; use Hyperf\Amqp\Message\ProducerMessage;
use Meibuyu\Micro\Exceptions\HttpResponseException; use Meibuyu\Micro\Exceptions\HttpResponseException;
...@@ -17,23 +18,25 @@ class ExceptionLogProducer extends ProducerMessage ...@@ -17,23 +18,25 @@ class ExceptionLogProducer extends ProducerMessage
public function __construct($data) public function __construct($data)
{ {
$trace = explode("\n", $data['trace']);
try { try {
$data['operator'] = Auth::user()['name']; $data['operator'] = Auth::user()['name'];
} catch (HttpResponseException $e) { } catch (HttpResponseException $e) {
put_log('获取操作人失败; ' . $e->getMessage(), 'ExceptionLogProducer.log'); put_log('获取操作人失败; ' . $e->getMessage(), 'ExceptionLogProducer.log');
} }
// 排除依赖包文件和运行缓存文件
if (strpos($data['file'], '/vendor/') === false && strpos($data['file'], '/runtime/') === false) {
try { try {
exec("git blame -L {$data['line']},{$data['line']} {$data['file']}", $output); exec("git blame -L {$data['line']},{$data['line']} {$data['file']}", $output);
if (!empty($output[0]) && is_string($output[0])) { if (!empty($output[0]) && is_string($output[0])) {
preg_match('/(?<=\()[^ \)]+/', $output[0], $matches); preg_match('/(?<=\()[^ ]+/', $output[0], $matches);
if (!empty($matches[0])) { if (!empty($matches[0])) {
$data['coder'] = $matches[0]; $data['coder'] = $matches[0];
} }
} }
} catch (\Exception $e) { } catch (Exception $e) {
put_log('获取编码人失败; ' . $e->getMessage(), 'ExceptionLogProducer.log'); put_log('获取编码人失败; ' . $e->getMessage(), 'ExceptionLogProducer.log');
} }
}
$this->payload = $data; $this->payload = $data;
} }
......
...@@ -4,6 +4,7 @@ declare(strict_types=1); ...@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Meibuyu\Micro\Exceptions\Handler; namespace Meibuyu\Micro\Exceptions\Handler;
use Exception;
use Hyperf\Amqp\Producer; use Hyperf\Amqp\Producer;
use Hyperf\Contract\ConfigInterface; use Hyperf\Contract\ConfigInterface;
use Hyperf\Contract\StdoutLoggerInterface; use Hyperf\Contract\StdoutLoggerInterface;
...@@ -69,7 +70,7 @@ class AppExceptionHandler extends ExceptionHandler ...@@ -69,7 +70,7 @@ class AppExceptionHandler extends ExceptionHandler
$exceptionLogProducer = new ExceptionLogProducer($data); $exceptionLogProducer = new ExceptionLogProducer($data);
$producer = $this->container->get(Producer::class); $producer = $this->container->get(Producer::class);
$producer->produce($exceptionLogProducer); $producer->produce($exceptionLogProducer);
} catch (\Exception $e) { } catch (Exception $e) {
put_log('异常日志失败; ' . $e->getMessage(), 'ExceptionLogProducer.log'); put_log('异常日志失败; ' . $e->getMessage(), 'ExceptionLogProducer.log');
} }
$msg = sprintf('%s[%s] in %s', $message, $line, $file); $msg = sprintf('%s[%s] in %s', $message, $line, $file);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment