feat: 添加请求日志记录和 gRPC 连接快照功能
- 引入 `AndroidRequestLogHelper` 以记录请求日志 - 新增 `AndroidGrpcConnectionSnapshotVO` 和 `AndroidGrpcConnectionDetailVO` 类,用于表示 gRPC 连接快照和详情dev_na
parent
92a12c4c81
commit
3860ba3e00
|
|
@ -0,0 +1,21 @@
|
|||
package com.imeeting.dto.android;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Schema(description = "Android gRPC 连接详情")
|
||||
public class AndroidGrpcConnectionDetailVO {
|
||||
|
||||
@Schema(description = "连接ID")
|
||||
private String connectionId;
|
||||
|
||||
@Schema(description = "设备ID")
|
||||
private String deviceId;
|
||||
|
||||
@Schema(description = "租户ID")
|
||||
private Long tenantId;
|
||||
|
||||
@Schema(description = "用户ID")
|
||||
private Long userId;
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
package com.imeeting.dto.android;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Schema(description = "Android gRPC 连接快照")
|
||||
public class AndroidGrpcConnectionSnapshotVO {
|
||||
|
||||
@Schema(description = "当前连接总数")
|
||||
private int connectionCount;
|
||||
|
||||
@Schema(description = "连接详情列表")
|
||||
private List<AndroidGrpcConnectionDetailVO> connections;
|
||||
}
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
package com.imeeting.support;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public final class AndroidRequestLogHelper {
|
||||
|
||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
|
||||
private AndroidRequestLogHelper() {
|
||||
}
|
||||
|
||||
public static void logRequest(Logger log, String moduleName, String apiName, Object... keyValues) {
|
||||
log.info("[{}]{},请求时间:{},请求参数:{}",
|
||||
moduleName,
|
||||
apiName,
|
||||
LocalDateTime.now(),
|
||||
toJson(buildParams(keyValues)));
|
||||
}
|
||||
|
||||
private static Map<String, Object> buildParams(Object... keyValues) {
|
||||
Map<String, Object> params = new LinkedHashMap<>();
|
||||
if (keyValues == null) {
|
||||
return params;
|
||||
}
|
||||
for (int i = 0; i + 1 < keyValues.length; i += 2) {
|
||||
Object key = keyValues[i];
|
||||
if (key == null) {
|
||||
continue;
|
||||
}
|
||||
params.put(String.valueOf(key), sanitizeValue(keyValues[i + 1]));
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
private static Object sanitizeValue(Object value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
if (value instanceof MultipartFile file) {
|
||||
Map<String, Object> fileInfo = new LinkedHashMap<>();
|
||||
fileInfo.put("name", file.getName());
|
||||
fileInfo.put("originalFilename", file.getOriginalFilename());
|
||||
fileInfo.put("size", file.getSize());
|
||||
return fileInfo;
|
||||
}
|
||||
if (value instanceof MultipartFile[] files) {
|
||||
return Arrays.stream(files).map(AndroidRequestLogHelper::sanitizeValue).toList();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
private static String toJson(Object value) {
|
||||
try {
|
||||
return OBJECT_MAPPER.writeValueAsString(value);
|
||||
} catch (JsonProcessingException e) {
|
||||
return String.valueOf(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue