feat(logging): 引入SLF4J日志框架并替换原有打印方式- 添加SLF4J日志依赖并初始化Logger实例- 将System.out和System.err输出替换为info、warn和error级别日志

- 统一异常日志记录格式,保留堆栈信息
- 新增SpringBootStartApplication类支持WAR包部署方式
dev
wangyan 2025-10-30 19:11:53 +08:00
parent 0404522f9c
commit 04fad5cb9e
3 changed files with 28 additions and 7 deletions

View File

@ -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启动类
}
}

View File

@ -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);
}
}
}

View File

@ -13,5 +13,8 @@ spring:
password: Zcloud@redis16379
database: 10
port: 16379
logging:
level:
com.netsdk: INFO
modbus:
port: 18888