diff --git a/src/main/java/aiyh/utils/Util.java b/src/main/java/aiyh/utils/Util.java index 22e6544..962df09 100644 --- a/src/main/java/aiyh/utils/Util.java +++ b/src/main/java/aiyh/utils/Util.java @@ -3072,20 +3072,25 @@ public class Util extends weaver.general.Util { Matcher matcher = compile.matcher(logStr); int n = 0; while (matcher.find()) { + if (n + 1 > args.length) { + break; + } logStr = logStr.replaceFirst(pattern, "{" + n++ + "}"); } - Object arg = args[args.length - 1]; - if (arg instanceof Throwable) { - for (int i = 0; i < args.length - 1; i++) { - pattern = "\\{" + i + "}"; - logStr = logStr.replaceFirst(pattern, String.valueOf(args[i].toString())); + try { + Object arg = args[args.length - 1]; + if (arg instanceof Throwable) { + for (int i = 0; i < args.length - 1; i++) { + pattern = "\\{" + i + "}"; + logStr = logStr.replaceFirst(pattern, String.valueOf(args[i])); + } + return logStr + "\n" + getErrString((Throwable) arg); } - return logStr + "\n" + getErrString((Throwable) arg); + } catch (Exception ignore) { } - int i = 0; - for (Object o : args) { - pattern = "\\{" + i++ + "}"; - logStr = logStr.replaceFirst(pattern, String.valueOf(o)); + for (int i = 0; i < args.length; i++) { + pattern = "\\{" + i + "}"; + logStr = logStr.replaceFirst(pattern, String.valueOf(args[i])); } return logStr; } catch (Exception e) { diff --git a/src/main/java/aiyh/utils/httpUtil/util/HttpUtils.java b/src/main/java/aiyh/utils/httpUtil/util/HttpUtils.java index 2c3e946..6ea581f 100644 --- a/src/main/java/aiyh/utils/httpUtil/util/HttpUtils.java +++ b/src/main/java/aiyh/utils/httpUtil/util/HttpUtils.java @@ -121,11 +121,11 @@ public class HttpUtils { String str = sqlBuilder.toString().trim(); String removeSeparator = "&"; if (str.endsWith(removeSeparator)) { -// 如果以分&号结尾,则去除&号 + // 如果以分&号结尾,则去除&号 str = str.substring(0, str.length() - 1); } if (str.trim().startsWith(removeSeparator)) { -// 如果以&开头,则去除& + // 如果以&开头,则去除& str = str.substring(1); } return str; @@ -991,7 +991,7 @@ public class HttpUtils { nvps.add(new BasicNameValuePair(entry.getKey(), JSON.toJSONString(entry.getValue()))); } httpPost.setEntity(new UrlEncodedFormEntity(nvps)); -// } else if (contentType.toUpperCase().startsWith(HttpArgsType.APPLICATION_JSON.toUpperCase())) { + // } else if (contentType.toUpperCase().startsWith(HttpArgsType.APPLICATION_JSON.toUpperCase())) { } else { StringEntity stringEntity; if (params.containsKey(JSON_PARAM_KEY)) { @@ -1020,8 +1020,12 @@ public class HttpUtils { */ private HttpPost uploadFileByInputStream(String url, List multipartFileList, Map params, Map headers) { - log.info(Util.logStr("start request : url is [{}]" + - "", url)); + log.info(Util.logStr("start request : url is [{}],other param [\n{}\n],heard [\n{}\n]", url, JSONObject.toJSONString(params, + SerializerFeature.PrettyFormat, + SerializerFeature.WriteDateUseDateFormat), + JSONObject.toJSONString(headers, + SerializerFeature.PrettyFormat, + SerializerFeature.WriteDateUseDateFormat))); HttpUtilParamInfo httpUtilParamInfo = new HttpUtilParamInfo(); httpUtilParamInfo.setParams(params); httpUtilParamInfo.setUrl(url); @@ -1069,8 +1073,12 @@ public class HttpUtils { */ private HttpPut uploadFileByInputStreamPut(String url, List multipartFileList, Map params, Map headers) { - log.info(Util.logStr("start request : url is [{}]" + - "", url)); + log.info(Util.logStr("start request : url is [{}],other param [\n{}\n],heard [\n{}\n]", url, JSONObject.toJSONString(params, + SerializerFeature.PrettyFormat, + SerializerFeature.WriteDateUseDateFormat), + JSONObject.toJSONString(headers, + SerializerFeature.PrettyFormat, + SerializerFeature.WriteDateUseDateFormat))); HttpUtilParamInfo httpUtilParamInfo = new HttpUtilParamInfo(); httpUtilParamInfo.setParams(params); httpUtilParamInfo.setUrl(url); diff --git a/src/test/java/youhong/ai/pcn/TestOrganization.java b/src/test/java/youhong/ai/pcn/TestOrganization.java index 07921f2..81c4f3b 100644 --- a/src/test/java/youhong/ai/pcn/TestOrganization.java +++ b/src/test/java/youhong/ai/pcn/TestOrganization.java @@ -110,8 +110,8 @@ public class TestOrganization extends BaseTest { public void testStaticLog() { log.info("哈哈哈好的方式"); String testStr = "weaver.xuanran.wang.schroeder.cus_field_value.PushSealTaskSealValue?sealSnField=sealSn&sealNumField=sealNum&sealSnCusSql=`select\n" + - "? from jkfdjsfk where id\n" + - "=1`&sealNumCusSql=`select case ? when 0 then htzyzcs when 1 then gzcs else frzcs end from formtable_main_22_dt1 where id = {?dt.id}`&cus=`select * from table id = ? and test = ?`"; + " ? from jkfdjsfk where id\n" + + " =1`&sealNumCusSql=`select case ? when 0 then htzyzcs when 1 then gzcs else frzcs end from formtable_main_22_dt1 where id = {?dt.id}`&hah=liuliu&cus=`select? * fr$%&#@!)(<>?/\\{}「」【【】[]~、asfom table where id = '' and teset = #{name}`&niua=卧槽"; Map stringStringMap = Util.parseCusInterfacePathParam(testStr); System.out.println(stringStringMap); System.out.println(JSON.toJSONString(stringStringMap)); @@ -140,7 +140,11 @@ public class TestOrganization extends BaseTest { if (paramValue != null && paramValue.startsWith("`") && paramValue.endsWith("`")) { } } + } + @Test + public void testLogStr() { + System.out.println(Util.logStr("ajsdf {} jasjdf {}", "asf", "asdfeag")); } @Test