Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
YZG
yzg-util
Commits
2a0ecb83
Commit
2a0ecb83
authored
May 12, 2022
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复等待时间
parent
669948f1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
92 additions
and
21 deletions
+92
-21
LogFilter.java
...rc/main/java/com/yanzuoguang/cloud/aop/log/LogFilter.java
+27
-0
LogFilterDefault.java
.../java/com/yanzuoguang/cloud/aop/log/LogFilterDefault.java
+52
-0
LogLocal.java
...src/main/java/com/yanzuoguang/cloud/aop/log/LogLocal.java
+13
-21
No files found.
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/aop/log/LogFilter.java
0 → 100644
View file @
2a0ecb83
package
com
.
yanzuoguang
.
cloud
.
aop
.
log
;
import
java.util.List
;
/**
* 日志过滤
*
* @author 颜佐光
*/
public
interface
LogFilter
{
/**
* 是否排除,排除后将不会再次过滤
*
* @param keys 关键字
* @return 是否排除
*/
boolean
logExpect
(
List
<
String
>
keys
);
/**
* 过滤日志
*
* @param keys 关键字
* @return 是否过滤
*/
boolean
logFilter
(
List
<
String
>
keys
);
}
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/aop/log/LogFilterDefault.java
0 → 100644
View file @
2a0ecb83
package
com
.
yanzuoguang
.
cloud
.
aop
.
log
;
import
com.yanzuoguang.cloud.CloudConfig
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
org.springframework.stereotype.Component
;
import
java.util.List
;
/**
* 日志默认过滤
*
* @author 颜佐光
*/
@Component
public
class
LogFilterDefault
implements
LogFilter
{
private
final
CloudConfig
cloudConfig
;
public
LogFilterDefault
(
CloudConfig
cloudConfig
)
{
this
.
cloudConfig
=
cloudConfig
;
}
@Override
public
boolean
logExpect
(
List
<
String
>
keys
)
{
if
(!
StringHelper
.
isEmpty
(
this
.
cloudConfig
.
getLogNotFilter
()))
{
for
(
String
key
:
keys
)
{
if
(
StringHelper
.
isEmpty
(
key
))
{
continue
;
}
if
(
key
.
toLowerCase
().
matches
(
this
.
cloudConfig
.
getLogNotFilter
()))
{
return
true
;
}
}
}
return
false
;
}
@Override
public
boolean
logFilter
(
List
<
String
>
keys
)
{
if
(!
StringHelper
.
isEmpty
(
this
.
cloudConfig
.
getLogFilter
()))
{
for
(
String
key
:
keys
)
{
if
(
StringHelper
.
isEmpty
(
key
))
{
continue
;
}
if
(
key
.
toLowerCase
().
matches
(
this
.
cloudConfig
.
getLogFilter
()))
{
return
true
;
}
}
}
return
false
;
}
}
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/aop/log/LogLocal.java
View file @
2a0ecb83
...
@@ -9,10 +9,7 @@ import com.yanzuoguang.util.vo.LogVo;
...
@@ -9,10 +9,7 @@ import com.yanzuoguang.util.vo.LogVo;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
java.util.ArrayList
;
import
java.util.*
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.ConcurrentHashMap
;
/**
/**
...
@@ -27,6 +24,7 @@ public class LogLocal implements ThreadNext.Next, InitializingBean {
...
@@ -27,6 +24,7 @@ public class LogLocal implements ThreadNext.Next, InitializingBean {
*/
*/
private
final
LogBase
logBase
;
private
final
LogBase
logBase
;
private
final
CloudConfig
cloudConfig
;
private
final
CloudConfig
cloudConfig
;
private
final
List
<
LogFilter
>
logFilters
;
/**
/**
* 超时状态
* 超时状态
*/
*/
...
@@ -37,9 +35,10 @@ public class LogLocal implements ThreadNext.Next, InitializingBean {
...
@@ -37,9 +35,10 @@ public class LogLocal implements ThreadNext.Next, InitializingBean {
*/
*/
protected
volatile
Map
<
String
,
Timeout
<
LogVo
>>
cache
=
new
ConcurrentHashMap
<>();
protected
volatile
Map
<
String
,
Timeout
<
LogVo
>>
cache
=
new
ConcurrentHashMap
<>();
public
LogLocal
(
LogBase
logBase
,
CloudConfig
cloudConfig
)
{
public
LogLocal
(
LogBase
logBase
,
CloudConfig
cloudConfig
,
List
<
LogFilter
>
logFilters
)
{
this
.
logBase
=
logBase
;
this
.
logBase
=
logBase
;
this
.
cloudConfig
=
cloudConfig
;
this
.
cloudConfig
=
cloudConfig
;
this
.
logFilters
=
logFilters
;
}
}
/**
/**
...
@@ -152,25 +151,18 @@ public class LogLocal implements ThreadNext.Next, InitializingBean {
...
@@ -152,25 +151,18 @@ public class LogLocal implements ThreadNext.Next, InitializingBean {
public
boolean
isLog
(
String
...
keys
)
{
public
boolean
isLog
(
String
...
keys
)
{
List
<
String
>
list
=
new
ArrayList
<>();
List
<
String
>
list
=
new
ArrayList
<>();
list
.
add
(
this
.
cloudConfig
.
getApplicationName
());
list
.
add
(
this
.
cloudConfig
.
getApplicationName
());
for
(
String
item
:
keys
)
{
list
.
addAll
(
Arrays
.
asList
(
keys
));
list
.
add
(
item
);
for
(
LogFilter
k
:
logFilters
)
{
}
if
(
k
.
logExpect
(
list
))
{
// 是否排除
return
true
;
boolean
notFilter
=
false
;
// 是否过滤
boolean
filter
=
false
;
for
(
String
item
:
list
)
{
if
(
item
==
null
)
{
continue
;
}
}
String
lower
=
item
.
toLowerCase
();
notFilter
=
notFilter
||
lower
.
matches
(
this
.
cloudConfig
.
getLogNotFilter
());
filter
=
filter
||
lower
.
matches
(
this
.
cloudConfig
.
getLogFilter
());
}
}
if
(
notFilter
)
{
for
(
LogFilter
k
:
logFilters
)
{
return
false
;
if
(
k
.
logFilter
(
list
))
{
return
false
;
}
}
}
return
filter
;
return
true
;
}
}
/**
/**
...
...
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