Commit 8a33955c authored by 王源's avatar 王源 🎧

Merge branch 'feature/exception' into test

parents 5123a1cb b0e265fd
......@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Meibuyu\Micro\Amqp\Producer;
use Exception;
use Hyperf\Amqp\Annotation\Producer;
use Hyperf\Amqp\Message\ProducerMessage;
use Meibuyu\Micro\Exceptions\HttpResponseException;
......@@ -17,22 +18,24 @@ class ExceptionLogProducer extends ProducerMessage
public function __construct($data)
{
$trace = explode("\n", $data['trace']);
try {
$data['operator'] = Auth::user()['name'];
} catch (HttpResponseException $e) {
put_log('获取操作人失败; ' . $e->getMessage(), 'ExceptionLogProducer.log');
}
try {
exec("git blame -L {$data['line']},{$data['line']} {$data['file']}", $output);
if (!empty($output[0]) && is_string($output[0])) {
preg_match('/(?<=\()[^ \)]+/', $output[0], $matches);
if (!empty($matches[0])) {
$data['coder'] = $matches[0];
// 排除依赖包文件和运行缓存文件
if (strpos($data['file'], '/vendor/') === false && strpos($data['file'], '/runtime/') === false) {
try {
exec("git blame -L {$data['line']},{$data['line']} {$data['file']}", $output);
if (!empty($output[0]) && is_string($output[0])) {
preg_match('/(?<=\()[^ ]+/', $output[0], $matches);
if (!empty($matches[0])) {
$data['coder'] = $matches[0];
}
}
} catch (Exception $e) {
put_log('获取编码人失败; ' . $e->getMessage(), 'ExceptionLogProducer.log');
}
} catch (\Exception $e) {
put_log('获取编码人失败; ' . $e->getMessage(), 'ExceptionLogProducer.log');
}
$this->payload = $data;
}
......
......@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Meibuyu\Micro\Exceptions\Handler;
use Exception;
use Hyperf\Amqp\Producer;
use Hyperf\Contract\ConfigInterface;
use Hyperf\Contract\StdoutLoggerInterface;
......@@ -69,7 +70,7 @@ class AppExceptionHandler extends ExceptionHandler
$exceptionLogProducer = new ExceptionLogProducer($data);
$producer = $this->container->get(Producer::class);
$producer->produce($exceptionLogProducer);
} catch (\Exception $e) {
} catch (Exception $e) {
put_log('异常日志失败; ' . $e->getMessage(), 'ExceptionLogProducer.log');
}
$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