(improvement)(code) Replace e.printStackTrace() with logger.error. (#1156)

This commit is contained in:
lexluo09
2024-06-15 18:26:52 +08:00
committed by GitHub
parent b5cc450758
commit f2a12e56b7
9 changed files with 39 additions and 36 deletions

View File

@@ -5,6 +5,7 @@ import com.tencent.supersonic.auth.api.authentication.constant.UserConstants;
import com.tencent.supersonic.auth.authentication.service.UserServiceImpl;
import com.tencent.supersonic.auth.authentication.utils.UserTokenUtils;
import com.tencent.supersonic.common.util.S2ThreadContext;
import lombok.extern.slf4j.Slf4j;
import org.apache.catalina.connector.RequestFacade;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.util.Strings;
@@ -17,7 +18,7 @@ import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.List;
@Slf4j
public abstract class AuthenticationInterceptor implements HandlerInterceptor {
@@ -64,7 +65,7 @@ public abstract class AuthenticationInterceptor implements HandlerInterceptor {
return StringUtils.isNotBlank(appId);
}
protected void reflectSetparam(HttpServletRequest request, String key, String value) {
protected void reflectSetParam(HttpServletRequest request, String key, String value) {
try {
if (request instanceof StandardMultipartHttpServletRequest) {
RequestFacade servletRequest =
@@ -98,7 +99,7 @@ public abstract class AuthenticationInterceptor implements HandlerInterceptor {
o2.addValue(key).setString(value);
}
} catch (Exception e) {
e.printStackTrace();
log.error("reflectSetParam error:", e);
}
}
}

View File

@@ -67,7 +67,7 @@ public class DefaultAuthenticationInterceptor extends AuthenticationInterceptor
private void setFakerUser(HttpServletRequest request) {
String token = userTokenUtils.generateAdminToken(request);
reflectSetparam(request, authenticationConfig.getTokenHttpHeaderKey(), token);
reflectSetParam(request, authenticationConfig.getTokenHttpHeaderKey(), token);
setContext(User.getFakeUser().getName(), request);
}

View File

@@ -3,8 +3,9 @@ package com.tencent.supersonic.common.util;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.Base64;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class MD5Util {
@@ -44,7 +45,7 @@ public class MD5Util {
}
}
} catch (Exception e) {
e.printStackTrace();
log.error("", e);
}
if (isUpper) {

View File

@@ -12,8 +12,9 @@ import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class YamlUtils {
/**
@@ -30,7 +31,7 @@ public class YamlUtils {
try {
return mapper.readValue(yamlStr, clazz);
} catch (JsonProcessingException e) {
e.printStackTrace();
log.error("", e);
}
return null;
}
@@ -53,7 +54,7 @@ public class YamlUtils {
.replaceAll("\"false\"", "false")
.replaceAll("\"False\"", "false");
} catch (IOException e) {
e.printStackTrace();
log.error("", e);
}
return null;
}

View File

@@ -32,8 +32,7 @@ public class LocalFileConfig {
try {
return HanlpHelper.getHanlpPropertiesPath();
} catch (FileNotFoundException e) {
log.warn("getDictDirectoryPrefixDir error: " + e);
e.printStackTrace();
log.error("getDictDirectoryPrefixDir error: ", e);
}
return "";
}

View File

@@ -59,16 +59,16 @@ public class SqlQueryApiController {
chatQueryService.correct(querySqlReq, user);
return querySqlReq;
}).collect(Collectors.toList());
List<CompletableFuture<SemanticQueryResp>> futures = semanticQueryReqs.stream()
.map(querySqlReq -> CompletableFuture.supplyAsync(() -> {
try {
return queryService.queryByReq(querySqlReq, user);
} catch (Exception e) {
e.printStackTrace();
log.error("querySqlReq:{},queryByReq error:", querySqlReq, e);
return new SemanticQueryResp();
}
}))
.collect(Collectors.toList());
})).collect(Collectors.toList());
return futures.stream().map(CompletableFuture::join).collect(Collectors.toList());
}

View File

@@ -1,5 +1,11 @@
package com.tencent.supersonic.headless.server.utils;
import static com.tencent.supersonic.common.pojo.Constants.AND_UPPER;
import static com.tencent.supersonic.common.pojo.Constants.APOSTROPHE;
import static com.tencent.supersonic.common.pojo.Constants.COMMA;
import static com.tencent.supersonic.common.pojo.Constants.POUND;
import static com.tencent.supersonic.common.pojo.Constants.SPACE;
import com.google.common.base.Strings;
import com.tencent.supersonic.auth.api.authentication.pojo.User;
import com.tencent.supersonic.common.pojo.Aggregator;
@@ -34,13 +40,6 @@ import com.tencent.supersonic.headless.server.service.MetricService;
import com.tencent.supersonic.headless.server.service.ModelService;
import com.tencent.supersonic.headless.server.service.QueryService;
import com.tencent.supersonic.headless.server.service.TagMetaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
@@ -53,12 +52,12 @@ import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.StringJoiner;
import static com.tencent.supersonic.common.pojo.Constants.AND_UPPER;
import static com.tencent.supersonic.common.pojo.Constants.APOSTROPHE;
import static com.tencent.supersonic.common.pojo.Constants.COMMA;
import static com.tencent.supersonic.common.pojo.Constants.POUND;
import static com.tencent.supersonic.common.pojo.Constants.SPACE;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
@Slf4j
@Component
@@ -87,10 +86,10 @@ public class DictUtils {
private final TagMetaService tagMetaService;
public DictUtils(DimensionService dimensionService,
MetricService metricService,
QueryService queryService,
ModelService modelService,
@Lazy TagMetaService tagMetaService) {
MetricService metricService,
QueryService queryService,
ModelService modelService,
@Lazy TagMetaService tagMetaService) {
this.dimensionService = dimensionService;
this.metricService = metricService;
this.queryService = queryService;
@@ -190,7 +189,7 @@ public class DictUtils {
constructDictLines(valueAndFrequencyPair, lines, nature);
addWhiteValueLines(dictItemResp, lines, nature);
} catch (Exception e) {
e.printStackTrace();
log.error("dictItemResp:{},fetchItemValue error:", dictItemResp, e);
}
return lines;
}

View File

@@ -130,7 +130,7 @@ public class StatUtils {
queryStatInfo.setModelId(queryTagReq.getModelIds().get(0));
}
} catch (JsonProcessingException e) {
e.printStackTrace();
log.error("", e);
}
StatUtils.set(queryStatInfo);
@@ -198,7 +198,7 @@ public class StatUtils {
queryStatInfo.setModelId(queryStructReq.getModelIds().get(0));
}
} catch (JsonProcessingException e) {
e.printStackTrace();
log.error("", e);
}
StatUtils.set(queryStatInfo);

View File

@@ -6,6 +6,7 @@ import static org.junit.Assert.assertTrue;
import com.tencent.supersonic.auth.api.authentication.utils.UserHolder;
import com.tencent.supersonic.auth.authentication.strategy.FakeUserStrategy;
import com.tencent.supersonic.headless.server.listener.FlightSqlListener;
import lombok.extern.slf4j.Slf4j;
import org.apache.arrow.flight.CallHeaders;
import org.apache.arrow.flight.FlightCallHeaders;
import org.apache.arrow.flight.FlightClient;
@@ -18,6 +19,7 @@ import org.apache.arrow.memory.RootAllocator;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
@Slf4j
public class FlightSqlTest extends BaseTest {
@@ -59,7 +61,7 @@ public class FlightSqlTest extends BaseTest {
assertEquals(2, colCnt);
assertTrue(rowCnt > 0);
} catch (Exception e) {
e.printStackTrace();
log.error("", e);
}
}
@@ -95,7 +97,7 @@ public class FlightSqlTest extends BaseTest {
assertEquals(2, colCnt);
assertTrue(rowCnt > 0);
} catch (Exception e) {
e.printStackTrace();
log.error("", e);
}
}
}