Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
孙克
/
smf-core
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 8db12cdb
由
LN
编写于
2026-01-15 13:30:26 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
api日志打印到单独文件中
1 个父辈
f17887c5
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
96 行增加
和
19 行删除
pom.xml
src/main/java/com/neotel/smfcore/common/apilog/ApiLog.java
src/main/java/com/neotel/smfcore/common/utils/HttpHelper.java
src/main/resources/log4j2-spring.xml
pom.xml
查看文件 @
8db12cd
...
...
@@ -16,7 +16,7 @@
<description>
SMF project for Spring Boot
</description>
<properties>
<maven.build.timestamp.format>
M.ddHHmm
</maven.build.timestamp.format>
<main.version>
5
.${maven.build.timestamp}
</main.version>
<main.version>
6
.${maven.build.timestamp}
</main.version>
<app.version>
${main.version}
</app.version>
<java.version>
1.8
</java.version>
<jjwt.version>
0.11.1
</jjwt.version>
...
...
src/main/java/com/neotel/smfcore/common/apilog/ApiLog.java
0 → 100644
查看文件 @
8db12cd
package
com
.
neotel
.
smfcore
.
common
.
apilog
;
import
lombok.extern.slf4j.Slf4j
;
import
java.text.MessageFormat
;
import
java.util.Arrays
;
@Slf4j
public
class
ApiLog
{
public
static
void
info
(
String
msg
)
{
log
.
info
(
msg
);
}
public
static
void
info
(
String
pattern
,
Object
...
args
)
{
log
.
info
(
format
(
pattern
,
args
));
}
public
static
void
debug
(
String
msg
)
{
log
.
debug
(
msg
);
}
public
static
void
debug
(
String
pattern
,
Object
...
args
)
{
log
.
debug
(
format
(
pattern
,
args
));
}
public
static
void
trace
(
String
msg
)
{
log
.
trace
(
msg
);
}
public
static
void
trace
(
String
pattern
,
Object
...
args
)
{
log
.
trace
(
format
(
pattern
,
args
));
}
public
static
void
error
(
String
msg
)
{
log
.
error
(
msg
);
}
public
static
void
error
(
String
pattern
,
Object
...
args
)
{
log
.
error
(
format
(
pattern
,
args
));
}
public
static
void
error
(
String
msg
,
Exception
e
)
{
log
.
error
(
msg
,
e
);
}
public
static
void
error
(
String
pattern
,
Exception
e
,
Object
...
args
)
{
log
.
error
(
format
(
pattern
,
args
),
e
);
}
public
static
void
warn
(
String
msg
)
{
log
.
warn
(
msg
);
}
public
static
void
warn
(
String
pattern
,
Object
...
args
)
{
log
.
warn
(
format
(
pattern
,
args
));
}
private
static
String
format
(
String
pattern
,
Object
...
args
)
{
if
(
args
==
null
||
args
.
length
==
0
)
{
return
pattern
;
}
try
{
return
MessageFormat
.
format
(
pattern
,
args
);
}
catch
(
Exception
e
)
{
return
pattern
+
" "
+
Arrays
.
toString
(
args
);
}
}
}
src/main/java/com/neotel/smfcore/common/utils/HttpHelper.java
查看文件 @
8db12cd
...
...
@@ -3,6 +3,7 @@ package com.neotel.smfcore.common.utils;
import
cn.hutool.core.util.ObjectUtil
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.neotel.smfcore.common.apilog.ApiLog
;
import
com.neotel.smfcore.common.exception.ApiException
;
import
com.neotel.smfcore.custom.micron1053.bean.MicronResult
;
import
lombok.extern.slf4j.Slf4j
;
...
...
@@ -319,21 +320,11 @@ public class HttpHelper {
if
(
ObjectUtil
.
isEmpty
(
url
))
{
return
new
MicronResult
();
}
url
=
encodeURL
(
url
);
url
=
encodeURL
(
url
);
HttpGet
httpGet
=
new
HttpGet
(
url
);
httpGet
.
addHeader
(
"Content-Type"
,
"application/json;charset=utf-8"
);
// // 设置请求参数
// if (params != null && !params.isEmpty()) {
// ObjectMapper mapper = new ObjectMapper();
// try {
// String requestBody = mapper.writeValueAsString(params);
// httpGet.seb(new StringEntity(requestBody,CONTENT_CHARSET));
// } catch (JsonProcessingException e) {
// throw new ApiException("Request params to [" + url + "] failed:" + e.getMessage());
// } catch (Exception e) {
// throw new ApiException("Request params to [" + url + "] failed:" + e.getMessage());
// }
// }
ApiLog
.
info
(
"Request to ["
+
url
+
"] "
);
try
{
CloseableHttpClient
httpClient
=
HttpClients
.
createDefault
();
RequestConfig
requestConfig
=
RequestConfig
.
custom
().
setConnectTimeout
(
CONNECTION_TIMEOUT
).
setConnectionRequestTimeout
(
60000
).
setSocketTimeout
(
60000
).
build
();
...
...
@@ -344,14 +335,17 @@ public class HttpHelper {
//System.out.println(response.getStatusLine().getStatusCode() + "\n");
HttpEntity
entity
=
response
.
getEntity
();
String
responseContent
=
EntityUtils
.
toString
(
entity
,
CONTENT_CHARSET
);
log
.
info
(
"Request to ["
+
url
+
"] response: code="
+
code
+
",responseContent="
+
responseContent
);
MicronResult
result
=
new
MicronResult
(
code
,
responseContent
);
log
.
info
(
"Request to ["
+
url
+
"] response: code="
+
code
+
",responseContent="
+
responseContent
);
ApiLog
.
info
(
"Request to ["
+
url
+
"] response: code="
+
code
+
",responseContent="
+
responseContent
);
MicronResult
result
=
new
MicronResult
(
code
,
responseContent
);
response
.
close
();
httpClient
.
close
();
return
result
;
}
catch
(
Exception
e
)
{
throw
new
ApiException
(
"Request to ["
+
url
+
"] failed:"
+
e
.
getMessage
());
}
catch
(
Exception
e
)
{
ApiLog
.
error
(
"Request to ["
+
url
+
"] failed: "
+
e
);
throw
new
ApiException
(
"Request to ["
+
url
+
"] failed: "
+
e
.
getMessage
());
}
}
...
...
@@ -375,6 +369,7 @@ public class HttpHelper {
ObjectMapper
mapper
=
new
ObjectMapper
();
String
requestBody
=
mapper
.
writeValueAsString
(
params
);
httpPost
.
setEntity
(
new
StringEntity
(
requestBody
,
CONTENT_CHARSET
));
ApiLog
.
info
(
"Request to ["
+
url
+
"] requestBody="
+
requestBody
);
}
catch
(
JsonProcessingException
e
)
{
throw
new
ApiException
(
"Request params to ["
+
url
+
"] Json failed:"
+
e
.
getMessage
());
}
catch
(
Exception
e
)
{
...
...
@@ -390,13 +385,15 @@ public class HttpHelper {
String
responseContent
=
EntityUtils
.
toString
(
entity
,
CONTENT_CHARSET
);
int
code
=
response
.
getStatusLine
().
getStatusCode
();
log
.
info
(
"Request to ["
+
url
+
"] response: code="
+
code
+
",responseContent="
+
responseContent
);
ApiLog
.
info
(
"Request to ["
+
url
+
"] response: code="
+
code
+
",responseContent="
+
responseContent
);
MicronResult
result
=
new
MicronResult
(
code
,
responseContent
);
response
.
close
();
httpClient
.
close
();
return
result
;
}
catch
(
Exception
e
)
{
throw
new
ApiException
(
"Request to ["
+
url
+
"] failed:"
+
e
.
getMessage
());
ApiLog
.
error
(
"Request to ["
+
url
+
"] failed: "
+
e
);
throw
new
ApiException
(
"Request to ["
+
url
+
"] failed: "
+
e
.
getMessage
());
}
}
catch
(
Exception
e
)
{
...
...
src/main/resources/log4j2-spring.xml
查看文件 @
8db12cd
...
...
@@ -3,6 +3,8 @@
<Properties>
<Property
name=
"LOG_HOME"
>
logs
</Property>
<Property
name=
"LOG_NAME"
>
smf
</Property>
<Property
name=
"LOG_API_NAME"
>
apilog
</Property>
<Property
name=
"LOG_API_HOME"
>
logs/api
</Property>
</Properties>
<appenders>
<Console
name=
"Console"
target=
"SYSTEM_OUT"
>
...
...
@@ -15,12 +17,22 @@
</Policies>
<DefaultRolloverStrategy
max=
"180"
/>
</RollingFile>
<RollingFile
name=
"logApi"
fileName=
"${LOG_API_HOME}/${LOG_API_NAME}.txt"
filePattern=
"${LOG_API_HOME}/${LOG_API_NAME}.%d{yyyy-MM-dd}.txt"
append=
"true"
>
<PatternLayout
charset=
"UTF-8"
pattern=
"%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level- %msg%n"
/>
<Policies>
<TimeBasedTriggeringPolicy
modulate=
"true"
interval=
"1"
/>
</Policies>
<DefaultRolloverStrategy
max=
"180"
/>
</RollingFile>
</appenders>
<loggers>
<logger
name=
"org"
level=
"WARN"
>
</logger>
<logger
name=
"ro"
level=
"WARN"
>
</logger>
<logger
name=
"com.neotel.smfcore.common.apilog"
level=
"INFO"
additivity=
"false"
>
<appender-ref
ref=
"logApi"
/>
</logger>
<root
level=
"INFO"
>
<appender-ref
ref=
"Console"
/>
<appender-ref
ref=
"log"
/>
...
...
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论