Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
meibuyu-micro
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
without authentication
meibuyu-micro
Commits
b0e265fd
Commit
b0e265fd
authored
Mar 04, 2021
by
王源
🎧
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
异常收集排除依赖包文件和运行缓存文件
parent
be9d19f9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
10 deletions
+14
-10
ExceptionLogProducer.php
src/Amqp/Producer/ExceptionLogProducer.php
+12
-9
AppExceptionHandler.php
src/Exceptions/Handler/AppExceptionHandler.php
+2
-1
No files found.
src/Amqp/Producer/ExceptionLogProducer.php
View file @
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
;
}
...
...
src/Exceptions/Handler/AppExceptionHandler.php
View file @
b0e265fd
...
...
@@ -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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment