Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
meibuyu-common
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
0
Merge Requests
0
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-common
Commits
c701e9b9
Commit
c701e9b9
authored
Mar 01, 2023
by
zhangdongying
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 全局日志组件编写
parent
ac71db42
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
17 deletions
+11
-17
AppOperateLogService.php
src/GlobalLog/AppOperateLogService.php
+3
-0
OperateLogService.php
src/GlobalLog/Service/OperateLogService.php
+8
-5
RedisQueueService.php
src/GlobalLog/Service/RedisQueueService.php
+0
-12
No files found.
src/GlobalLog/AppOperateLogService.php
View file @
c701e9b9
...
...
@@ -87,6 +87,7 @@ class AppOperateLogService
)
{
return
$this
->
operateLogService
->
addOperateLog
(
make
(
RequestInterface
::
class
)
->
header
(
'hwq-request-id'
,
''
),
$this
->
config
->
get
(
'app_name'
),
Auth
::
id
()
??
0
,
Auth
::
user
()[
'name'
]
??
''
,
...
...
@@ -105,6 +106,7 @@ class AppOperateLogService
/**
* 添加系统操作日志
*
* @param string $requestId 请求ID
* @param string $action 方法全路径
* @param string $tableName 表名
* @param string $recordId 记录ID
...
...
@@ -128,6 +130,7 @@ class AppOperateLogService
)
{
return
$this
->
operateLogService
->
addOperateLog
(
''
,
$this
->
config
->
get
(
'app_name'
),
0
,
'system'
,
...
...
src/GlobalLog/Service/OperateLogService.php
View file @
c701e9b9
...
...
@@ -49,19 +49,19 @@ class OperateLogService
}
/**
*
将数组转换成JSON
*
生成唯一ID
*
* @param array $array 数组
* @return string
*/
public
static
function
encodeArrayToJson
(
array
$array
)
:
string
public
static
function
generateUniqueId
(
)
:
string
{
return
json_encode
(
$array
,
JSON_UNESCAPED_UNICODE
|
JSON_UNESCAPED_SLASHES
);
return
sha1
(
uniqid
(
''
,
true
)
.
mt_rand
(
10000
,
99999
)
);
}
/**
* 添加操作日志
*
* @param string $requestId 请求ID
* @param string $appName 项目名称
* @param int $operatorId 操作人ID
* @param string $operatorName 操作人名称
...
...
@@ -78,6 +78,7 @@ class OperateLogService
* @throws \Exception
*/
public
function
addOperateLog
(
string
$requestId
,
string
$appName
,
int
$operatorId
,
string
$operatorName
,
...
...
@@ -93,6 +94,8 @@ class OperateLogService
)
:
bool
{
$data
=
[
'log_sn'
=>
self
::
generateUniqueId
(),
'request_id'
=>
$requestId
,
'app_name'
=>
$appName
,
'operator_id'
=>
$operatorId
,
'operator_name'
=>
$operatorName
,
...
...
@@ -108,6 +111,6 @@ class OperateLogService
'created_at'
=>
date
(
'Y-m-d H:i:s'
),
];
return
(
bool
)
$this
->
queueService
->
push
(
$this
->
queue
,
self
::
encodeArrayToJson
(
$data
));
return
(
bool
)
$this
->
queueService
->
push
(
$this
->
queue
,
json_encode
(
$data
));
}
}
\ No newline at end of file
src/GlobalLog/Service/RedisQueueService.php
View file @
c701e9b9
...
...
@@ -42,16 +42,4 @@ class RedisQueueService
{
return
$this
->
redis
->
lPush
(
$queue
,
$data
);
}
/**
* 从队列阻塞拉取
*
* @param string $queue 队列名称
* @return int $timeout 超时秒数
* @throws \Exception
*/
public
function
blockPop
(
string
$queue
,
int
$timeout
)
{
return
$this
->
redis
->
brPop
(
$queue
,
$timeout
);
}
}
\ No newline at end of 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