字符串格式化输出修复
parent
3a2234cbcc
commit
0dde57349d
|
@ -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++ + "}");
|
||||
}
|
||||
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].toString()));
|
||||
logStr = logStr.replaceFirst(pattern, String.valueOf(args[i]));
|
||||
}
|
||||
return logStr + "\n" + getErrString((Throwable) arg);
|
||||
}
|
||||
int i = 0;
|
||||
for (Object o : args) {
|
||||
pattern = "\\{" + i++ + "}";
|
||||
logStr = logStr.replaceFirst(pattern, String.valueOf(o));
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
pattern = "\\{" + i + "}";
|
||||
logStr = logStr.replaceFirst(pattern, String.valueOf(args[i]));
|
||||
}
|
||||
return logStr;
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -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<HttpMultipartFile> multipartFileList,
|
||||
Map<String, Object> params, Map<String, String> 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<HttpMultipartFile> multipartFileList,
|
||||
Map<String, Object> params, Map<String, String> 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);
|
||||
|
|
|
@ -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<String, String> 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
|
||||
|
|
Loading…
Reference in New Issue