Browse Source

rev:日志优化

master
刘先源 1 month ago
parent
commit
5dea9d9b1f
  1. 6
      acs2/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java
  2. 5
      acs2/nladmin-system/src/main/java/org/nl/acs/ext/xg/XgHttpUtil.java
  3. 2
      acs2/nladmin-system/src/main/resources/config/application-dev2.yml
  4. 33
      acs2/nladmin-system/src/main/resources/log/AcsToXg.xml
  5. 1
      acs2/nladmin-system/src/main/resources/logback-spring.xml

6
acs2/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java

@ -60,7 +60,7 @@ public class WmsToAcsServiceImpl implements WmsToAcsService {
CreateTaskRequest tasks = JSON.toJavaObject(req, CreateTaskRequest.class); CreateTaskRequest tasks = JSON.toJavaObject(req, CreateTaskRequest.class);
JSONObject resultJson = new JSONObject(); JSONObject resultJson = new JSONObject();
CreateTaskResponse resp = new CreateTaskResponse(); CreateTaskResponse resp = new CreateTaskResponse();
log.info("createFromWms - 请求参数 {}", JSON.toJSON(resp)); log.info("createFromWms - 请求参数 {}", req.toString());
String request_no = tasks.getRequestNo(); String request_no = tasks.getRequestNo();
JSONArray errArr = new JSONArray(); JSONArray errArr = new JSONArray();
try { try {
@ -264,8 +264,6 @@ public class WmsToAcsServiceImpl implements WmsToAcsService {
resp.setErrArr(errArr); resp.setErrArr(errArr);
} }
log.info("createFromWms - 返回参数 {}", resultJson.toString());
} catch (Exception e) { } catch (Exception e) {
resp.setCode(400); resp.setCode(400);
resp.setMessage(e.getMessage()); resp.setMessage(e.getMessage());
@ -273,7 +271,7 @@ public class WmsToAcsServiceImpl implements WmsToAcsService {
resp.setRequestNo(request_no); resp.setRequestNo(request_no);
resp.setResponseDate(AgvUtil.getDate()); resp.setResponseDate(AgvUtil.getDate());
resp.setMessage("请求成功"); resp.setMessage("请求成功");
log.info("createFromWms - 返回参数 {}", JSON.toJSON(resp)); log.info("createFromWms - 返回参数 {}", resp.toString());
// LuceneLogDto logDto = LuceneLogDto.builder() // LuceneLogDto logDto = LuceneLogDto.builder()
// .requestparam(JSON.toJSON(resp).toString()) // .requestparam(JSON.toJSON(resp).toString())

5
acs2/nladmin-system/src/main/java/org/nl/acs/ext/xg/XgHttpUtil.java

@ -3,6 +3,7 @@ package org.nl.acs.ext.xg;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.nl.acs.config.AcsConfig; import org.nl.acs.config.AcsConfig;
import org.nl.acs.ext.RequestAdapter; import org.nl.acs.ext.RequestAdapter;
import org.nl.acs.ext.ResponseAdapter; import org.nl.acs.ext.ResponseAdapter;
@ -18,6 +19,7 @@ import org.springframework.stereotype.Component;
* @Date 2024/4/22 * @Date 2024/4/22
*/ */
@Component @Component
@Slf4j
public class XgHttpUtil { public class XgHttpUtil {
private static final RequestAdapter REQUEST_ADAPTER = new XgRequestAdapter(); private static final RequestAdapter REQUEST_ADAPTER = new XgRequestAdapter();
@ -46,6 +48,8 @@ public class XgHttpUtil {
@ToOthersInterfaceLog("ACS->AGV") @ToOthersInterfaceLog("ACS->AGV")
public <T, W> UnifiedResponse<T> sendPostRequest(String path, W requestParam) { public <T, W> UnifiedResponse<T> sendPostRequest(String path, W requestParam) {
log.info("sendPostRequest - 请求参数 {}", path + ":"+ requestParam.toString());
if (!StrUtil.equals(paramService.findByCode(AcsConfig.FORK_AGV).getValue(), "1")) { if (!StrUtil.equals(paramService.findByCode(AcsConfig.FORK_AGV).getValue(), "1")) {
return new UnifiedResponse<>(false, "未开启连接该系统!"); return new UnifiedResponse<>(false, "未开启连接该系统!");
} }
@ -56,6 +60,7 @@ public class XgHttpUtil {
.body(JSON.toJSONString(requestParam)) .body(JSON.toJSONString(requestParam))
.execute() .execute()
.body(); .body();
log.info("sendPostRequest - 返回参数 {}", body);
return RESPONSE_ADAPTER.adapt(body, null); return RESPONSE_ADAPTER.adapt(body, null);
} catch (Exception e) { } catch (Exception e) {
return new UnifiedResponse<>(false, e.getMessage()); return new UnifiedResponse<>(false, e.getMessage());

2
acs2/nladmin-system/src/main/resources/config/application-dev2.yml

@ -140,7 +140,7 @@ file:
avatarMaxSize: 5 avatarMaxSize: 5
logging: logging:
file: file:
path: C:\log\ACS path: C:\logs\ACS
config: classpath:logback-spring.xml config: classpath:logback-spring.xml
# Sa-Token配置 # Sa-Token配置

33
acs2/nladmin-system/src/main/resources/log/AcsToXg.xml

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<included>
<springProperty scope="context" name="logPath" source="logging.file.path" defaultValue="logs"/>
<property name="LOG_HOME" value="${logPath}"/>
<!-- 按照每天生成日志文件 -->
<appender name="XgHttpUtil" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!--日志文件输出的文件名-->
<FileNamePattern>${LOG_HOME}/ACS请求XG/%d{yyyy-MM-dd}.%i.log</FileNamePattern>
<!--日志文件保留天数-->
<maxHistory>15</maxHistory>
<!--单个日志最大容量 至少10MB才能看得出来-->
<maxFileSize>200MB</maxFileSize>
<!--所有日志最多占多大容量-->
<totalSizeCap>2GB</totalSizeCap>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
<charset>${log.charset}</charset>
</encoder>
</appender>
<appender name="asyncFileAppender" class="ch.qos.logback.classic.AsyncAppender">
<appender-ref ref="XgHttpUtil"/>
<!-- 设置队列大小,根据您的需求调整 -->
<queueSize>512</queueSize>
</appender>
<logger name="org.nl.acs.ext.xg.XgHttpUtil" level="info" additivity="true">
<appender-ref ref="asyncFileAppender"/>
</logger>
</included>

1
acs2/nladmin-system/src/main/resources/logback-spring.xml

@ -24,6 +24,7 @@ https://juejin.cn/post/6844903775631572999
<include resource="log/AcsToWms.xml"/> <include resource="log/AcsToWms.xml"/>
<include resource="log/WmsToAcs.xml"/> <include resource="log/WmsToAcs.xml"/>
<include resource="log/XgToAcs.xml"/> <include resource="log/XgToAcs.xml"/>
<include resource="log/AcsToXg.xml"/>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<!--withJansi 参数改为true--> <!--withJansi 参数改为true-->

Loading…
Cancel
Save