Commit b0e265fd authored by 王源's avatar 王源
Browse files

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

parent be9d19f9
Loading
Loading
Loading
Loading
+12 −9
Original line number Diff line number Diff line
@@ -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,23 +18,25 @@ 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');
        }
        // 排除依赖包文件和运行缓存文件
        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);
                    preg_match('/(?<=\()[^ ]+/', $output[0], $matches);
                    if (!empty($matches[0])) {
                        $data['coder'] = $matches[0];
                    }
                }
        } catch (\Exception $e) {
            } catch (Exception $e) {
                put_log('获取编码人失败; ' . $e->getMessage(), 'ExceptionLogProducer.log');
            }
        }
        $this->payload = $data;
    }

+2 −1
Original line number Diff line number Diff line
@@ -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);