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
8a33955c
Commit
8a33955c
authored
Mar 04, 2021
by
王源
🎧
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/exception' into test
parents
5123a1cb
b0e265fd
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 @
8a33955c
...
@@ -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,22 +18,24 @@ class ExceptionLogProducer extends ProducerMessage
...
@@ -17,22 +18,24 @@ 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'
);
}
}
try
{
// 排除依赖包文件和运行缓存文件
exec
(
"git blame -L
{
$data
[
'line'
]
}
,
{
$data
[
'line'
]
}
{
$data
[
'file'
]
}
"
,
$output
);
if
(
strpos
(
$data
[
'file'
],
'/vendor/'
)
===
false
&&
strpos
(
$data
[
'file'
],
'/runtime/'
)
===
false
)
{
if
(
!
empty
(
$output
[
0
])
&&
is_string
(
$output
[
0
]))
{
try
{
preg_match
(
'/(?<=\()[^ \)]+/'
,
$output
[
0
],
$matches
);
exec
(
"git blame -L
{
$data
[
'line'
]
}
,
{
$data
[
'line'
]
}
{
$data
[
'file'
]
}
"
,
$output
);
if
(
!
empty
(
$matches
[
0
]))
{
if
(
!
empty
(
$output
[
0
])
&&
is_string
(
$output
[
0
]))
{
$data
[
'coder'
]
=
$matches
[
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
;
$this
->
payload
=
$data
;
}
}
...
...
src/Exceptions/Handler/AppExceptionHandler.php
View file @
8a33955c
...
@@ -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
);
...
...
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