Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
file-service
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
Packages
Packages
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
SuperHive
back-end
file-service
Commits
e08a5d78
Commit
e08a5d78
authored
May 29, 2020
by
huangcb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化日志输出
parent
4c077489
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
7 deletions
+38
-7
CommonConstants.java
...om/esv/freight/file/common/constants/CommonConstants.java
+5
-0
RestLogFilter.java
...ava/com/esv/freight/file/common/filter/RestLogFilter.java
+29
-7
logback-spring.xml
src/main/resources/logback-spring.xml
+4
-0
No files found.
src/main/java/com/esv/freight/file/common/constants/CommonConstants.java
View file @
e08a5d78
...
@@ -49,6 +49,11 @@ public class CommonConstants {
...
@@ -49,6 +49,11 @@ public class CommonConstants {
**/
**/
public
static
final
String
SPRING_BOOT_ADMIN_PREFIX_URL
=
"/actuator"
;
public
static
final
String
SPRING_BOOT_ADMIN_PREFIX_URL
=
"/actuator"
;
/**
* 文件下载URL
**/
public
static
final
String
FILE_DOWNLOAD_PREFIX_URL
=
"/file/download/"
;
/**
/**
* 默认字符编码
* 默认字符编码
**/
**/
...
...
src/main/java/com/esv/freight/file/common/filter/RestLogFilter.java
View file @
e08a5d78
...
@@ -28,9 +28,16 @@ import java.util.Map;
...
@@ -28,9 +28,16 @@ import java.util.Map;
@Slf4j
@Slf4j
public
class
RestLogFilter
implements
Filter
{
public
class
RestLogFilter
implements
Filter
{
private
Map
<
String
,
Integer
>
API_BODY_LOG_MAP
=
new
HashMap
<>();
@Override
@Override
public
void
init
(
FilterConfig
filterConfig
)
{
public
void
init
(
FilterConfig
filterConfig
)
{
// 设置API日志级别[5->4->3->2->1->0]:Fatal->error->warn->info->debug->trace
API_BODY_LOG_MAP
.
put
(
"/file/upload/single"
,
1
);
API_BODY_LOG_MAP
.
put
(
"/file/download/getFileData"
,
2
);
API_BODY_LOG_MAP
.
put
(
"/file/delete/single"
,
2
);;
API_BODY_LOG_MAP
.
put
(
"/file/ocr/idcard/front"
,
1
);
API_BODY_LOG_MAP
.
put
(
"/file/upload/imageWithWatermark"
,
1
);
}
}
@Override
@Override
...
@@ -132,9 +139,18 @@ public class RestLogFilter implements Filter {
...
@@ -132,9 +139,18 @@ public class RestLogFilter implements Filter {
// 日志输出请求体
// 日志输出请求体
if
(
url
.
startsWith
(
CommonConstants
.
SPRING_BOOT_ADMIN_PREFIX_URL
))
{
if
(
url
.
startsWith
(
CommonConstants
.
SPRING_BOOT_ADMIN_PREFIX_URL
))
{
log
.
debug
(
"[IP={}]收到{}请求,url:{},params:{}"
,
ReqUtils
.
getHttpClientIp
(
requestWrapper
),
method
,
url
,
reqBody
);
if
(
log
.
isDebugEnabled
())
{
log
.
debug
(
"[IP={}]收到{}请求,url:{},params:{}"
,
ReqUtils
.
getHttpClientIp
(
requestWrapper
),
method
,
url
,
reqBody
);
}
}
else
{
}
else
{
log
.
info
(
"[IP={}]收到{}请求,url:{},body:{}"
,
ReqUtils
.
getHttpClientIp
(
requestWrapper
),
method
,
url
,
reqBody
);
log
.
info
(
"[IP={}]收到{}请求,url:{}"
,
ReqUtils
.
getHttpClientIp
(
requestWrapper
),
method
,
url
);
if
(
API_BODY_LOG_MAP
.
containsKey
(
url
)
&&
1
<
API_BODY_LOG_MAP
.
get
(
url
))
{
log
.
info
(
"body:{}"
,
reqBody
);
}
else
{
if
(
log
.
isDebugEnabled
())
{
log
.
debug
(
"body:{}"
,
reqBody
);
}
}
}
}
}
}
...
@@ -163,13 +179,19 @@ public class RestLogFilter implements Filter {
...
@@ -163,13 +179,19 @@ public class RestLogFilter implements Filter {
log
.
error
(
e
.
getMessage
(),
e
);
log
.
error
(
e
.
getMessage
(),
e
);
}
}
String
url
=
requestWrapper
.
getRequestURI
();
String
url
=
requestWrapper
.
getRequestURI
();
if
(
CommonConstants
.
LOG_MAX_LENGTH
<
resBody
.
length
())
{
resBody
=
resBody
.
substring
(
0
,
CommonConstants
.
LOG_CUT_LENGTH
)
+
"……"
;
}
if
(
url
.
startsWith
(
CommonConstants
.
SPRING_BOOT_ADMIN_PREFIX_URL
))
{
if
(
url
.
startsWith
(
CommonConstants
.
SPRING_BOOT_ADMIN_PREFIX_URL
))
{
log
.
debug
(
"请求响应:{}"
,
resBody
);
if
(
log
.
isDebugEnabled
())
{
log
.
debug
(
"请求响应:{}"
,
resBody
);
}
}
else
if
(
url
.
startsWith
(
CommonConstants
.
FILE_DOWNLOAD_PREFIX_URL
))
{
if
(
log
.
isDebugEnabled
())
{
log
.
debug
(
"请求响应:{}"
,
resBody
);
}
else
{
log
.
info
(
"请求响应文件数据"
);
}
}
else
{
}
else
{
log
.
info
(
"请求响应:{}"
,
resBody
);
log
.
info
(
"请求响应:{}"
,
resBody
);
}
}
}
}
}
}
\ No newline at end of file
src/main/resources/logback-spring.xml
View file @
e08a5d78
...
@@ -47,6 +47,10 @@
...
@@ -47,6 +47,10 @@
<appender-ref
ref=
"CONSOLE_APPENDER"
/>
<appender-ref
ref=
"CONSOLE_APPENDER"
/>
<appender-ref
ref=
"FILE_APPENDER"
/>
<appender-ref
ref=
"FILE_APPENDER"
/>
</logger>
</logger>
<logger
name=
"com.esv.freight.file.common.filter"
level=
"INFO"
additivity=
"false"
>
<appender-ref
ref=
"CONSOLE_APPENDER"
/>
<appender-ref
ref=
"FILE_APPENDER"
/>
</logger>
<!--控制台和日志文件输出级别-->
<!--控制台和日志文件输出级别-->
<root
level=
"INFO"
additivity=
"false"
>
<root
level=
"INFO"
additivity=
"false"
>
...
...
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