From 04fad5cb9e323673c2221f9af836c4d11e21ee49 Mon Sep 17 00:00:00 2001 From: wangyan <405898180@qq.com> Date: Thu, 30 Oct 2025 19:11:53 +0800 Subject: [PATCH] =?UTF-8?q?feat(logging):=20=E5=BC=95=E5=85=A5SLF4J?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E6=A1=86=E6=9E=B6=E5=B9=B6=E6=9B=BF=E6=8D=A2?= =?UTF-8?q?=E5=8E=9F=E6=9C=89=E6=89=93=E5=8D=B0=E6=96=B9=E5=BC=8F-=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0SLF4J=E6=97=A5=E5=BF=97=E4=BE=9D=E8=B5=96?= =?UTF-8?q?=E5=B9=B6=E5=88=9D=E5=A7=8B=E5=8C=96Logger=E5=AE=9E=E4=BE=8B-?= =?UTF-8?q?=20=E5=B0=86System.out=E5=92=8CSystem.err=E8=BE=93=E5=87=BA?= =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E4=B8=BAinfo=E3=80=81warn=E5=92=8Cerror?= =?UTF-8?q?=E7=BA=A7=E5=88=AB=E6=97=A5=E5=BF=97=20-=20=E7=BB=9F=E4=B8=80?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E6=97=A5=E5=BF=97=E8=AE=B0=E5=BD=95=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=EF=BC=8C=E4=BF=9D=E7=95=99=E5=A0=86=E6=A0=88=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=20-=20=E6=96=B0=E5=A2=9ESpringBootStartApplication?= =?UTF-8?q?=E7=B1=BB=E6=94=AF=E6=8C=81WAR=E5=8C=85=E9=83=A8=E7=BD=B2?= =?UTF-8?q?=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/netsdk/SpringBootStartApplication.java | 17 +++++++++++++++++ .../ProvincialPlatformDataPushScheduled.java | 15 ++++++++------- src/main/resources/application.yml | 3 +++ 3 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 src/main/java/com/netsdk/SpringBootStartApplication.java diff --git a/src/main/java/com/netsdk/SpringBootStartApplication.java b/src/main/java/com/netsdk/SpringBootStartApplication.java new file mode 100644 index 0000000..c954b10 --- /dev/null +++ b/src/main/java/com/netsdk/SpringBootStartApplication.java @@ -0,0 +1,17 @@ +package com.netsdk; + +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; + +/** + * 说明:项目以war包方式运行时用到 + * 作者:luoxiaobao + * 官网:www.qdkjchina.com + */ +public class SpringBootStartApplication extends SpringBootServletInitializer { + + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { + return builder.sources(DahuaApplication.class); //这里要指向原先用main方法执行的FHmainApplication启动类 + } +} \ No newline at end of file diff --git a/src/main/java/com/netsdk/utils/ProvincialPlatformDataPushScheduled.java b/src/main/java/com/netsdk/utils/ProvincialPlatformDataPushScheduled.java index 314b52e..7bc6029 100644 --- a/src/main/java/com/netsdk/utils/ProvincialPlatformDataPushScheduled.java +++ b/src/main/java/com/netsdk/utils/ProvincialPlatformDataPushScheduled.java @@ -3,6 +3,8 @@ package com.netsdk.utils; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.netsdk.entity.PageData; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; @@ -26,6 +28,7 @@ import java.util.Map; */ @Component public class ProvincialPlatformDataPushScheduled { + private static final Logger logger = LoggerFactory.getLogger(ProvincialPlatformDataPushScheduled.class); private static final String URL = "http://1.71.182.111:86/iot-cascade-receive/iot/cascade/http-report"; //省平台推送接口 @Resource @@ -108,7 +111,7 @@ public class ProvincialPlatformDataPushScheduled { try { encrypt = AESUtil.encrypt(JSON.toJSONString(dataMap)); } catch (Exception e) { - System.out.println("实时数据AES加密出现错误!"); + logger.error("实时数据AES加密出现错误!", e); throw new RuntimeException(e); } baseMap.put("data", encrypt); @@ -170,7 +173,7 @@ public class ProvincialPlatformDataPushScheduled { try { encrypt = AESUtil.encrypt(JSON.toJSONString(alarmMap)); } catch (Exception e) { - System.out.println("实时数据AES加密出现错误!"); + logger.error("实时数据AES加密出现错误!", e); throw new RuntimeException(e); } baseMap.put("data", encrypt); @@ -197,14 +200,12 @@ public class ProvincialPlatformDataPushScheduled { //处理响应 if (response.getStatusCode().is2xxSuccessful()) { - System.out.println("数据推送成功,响应内容:" + response.getBody()); + logger.info("数据推送成功,响应内容:{}", response.getBody()); } else { - System.out.println("数据推送失败,状态码:" + response.getStatusCodeValue() + - ",响应内容:" + response.getBody()); + logger.warn("数据推送失败,状态码:{},响应内容:{}", response.getStatusCodeValue(), response.getBody()); } } catch (Exception e) { - System.err.println("数据推送发生异常:" + e.getMessage()); - e.printStackTrace(); + logger.error("数据推送发生异常:{}", e.getMessage(), e); } } } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index de3ff5b..b6eaa13 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -13,5 +13,8 @@ spring: password: Zcloud@redis16379 database: 10 port: 16379 +logging: + level: + com.netsdk: INFO modbus: port: 18888