perf[exception]: format the exception log

This commit is contained in:
godotg committed 2023-01-06 22:29:52 +08:00
1 parent d0aa341c06
commit 5ef04e0b17
10 files changed
+85 -72

No files matched your search

@@ -28,16 +28,48 @@ public class RunException extends RuntimeException {
super(message);
}
public RunException(String message, Throwable cause) {
super(message, cause);
}
public RunException(String template, Object arg1, Throwable cause) {
super(StringUtils.format(template, arg1), cause);
}
public RunException(String template, Object arg1, Object arg2, Throwable cause) {
super(StringUtils.format(template, arg1, arg2), cause);
}
public RunException(String template, Object arg1, Object arg2, Object arg3, Throwable cause) {
super(StringUtils.format(template, arg1, arg2, arg3), cause);
}
public RunException(String template, Object arg1, Object arg2, Object arg3, Object arg4, Throwable cause) {
super(StringUtils.format(template, arg1, arg2, arg3, arg4), cause);
}
public RunException(String template, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Throwable cause) {
super(StringUtils.format(template, arg1, arg2, arg3, arg4, arg5), cause);
}
public RunException(String template, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Throwable cause) {
super(StringUtils.format(template, arg1, arg2, arg3, arg4, arg5, arg6), cause);
}
public RunException(String template, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, Throwable cause) {
super(StringUtils.format(template, arg1, arg2, arg3, arg4, arg5, arg6, arg7), cause);
}
public RunException(String template, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, Object arg8, Throwable cause) {
super(StringUtils.format(template, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8), cause);
}
public RunException(String template, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, Object arg8, Object arg9, Throwable cause) {
super(StringUtils.format(template, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9), cause);
}
public RunException(String template, Object... args) {
super(StringUtils.format(template, args));
}
public RunException(Throwable cause, String message) {
super(message, cause);
}
public RunException(Throwable cause, String template, Object... args) {
super(StringUtils.format(template, args), cause);
}
}
@@ -47,7 +47,7 @@ public abstract class DomUtils {
try {
return MAPPER.readValue(xml, clazz);
} catch (IOException e) {
throw new RunException(e, "将xml字符串[xml:{}]转换为对象[{}]异常", xml, clazz);
throw new RunException("将xml字符串[xml:{}]转换为对象[{}]异常", xml, clazz, e);
}
}
@@ -57,7 +57,7 @@ public abstract class DomUtils {
var sr = f.createXMLStreamReader(new FileInputStream(xmlFile));
return MAPPER.readValue(sr, clazz);
} catch (Exception e) {
throw new RunException(e, "将xml文件[xml:{}]转换为对象[{}]异常", xmlFile, clazz);
throw new RunException("将xml文件[xml:{}]转换为对象[{}]异常", xmlFile, clazz, e);
}
}
@@ -65,7 +65,7 @@ public abstract class DomUtils {
try {
return MAPPER.readValue(xmlInputStream, clazz);
} catch (Exception e) {
throw new RunException(e, "将xmlInputStream转换为对象[{}]异常", clazz);
throw new RunException("将xmlInputStream转换为对象[{}]异常", clazz, e);
}
}
@@ -70,7 +70,7 @@ public abstract class JsonUtils {
try {
return MAPPER.readValue(json, clazz);
} catch (Exception e) {
throw new RunException(e, "将json字符串[json:{}]转换为对象[class:{}]时异常", json, clazz);
throw new RunException("将json字符串[json:{}]转换为对象[class:{}]时异常", json, clazz, e);
}
}
@@ -79,7 +79,7 @@ public abstract class JsonUtils {
try {
return MAPPER.writeValueAsString(object);
} catch (Exception e) {
throw new RunException(e, "将对象[object:{}]转换为json字符串时异常", object);
throw new RunException("将对象[object:{}]转换为json字符串时异常", object, e);
}
}
@@ -88,7 +88,7 @@ public abstract class JsonUtils {
try {
return MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(object);
} catch (Exception e) {
throw new RunException(e, "将对象[object:{}]转换为json字符串时异常", object);
throw new RunException("将对象[object:{}]转换为json字符串时异常", object, e);
}
}
@@ -99,7 +99,7 @@ public abstract class JsonUtils {
try {
return MAPPER_TURBO.readValue(json, clazz);
} catch (Exception e) {
throw new RunException(e, "将json字符串[json:{}]转换为对象[class:{}]时异常", json, clazz);
throw new RunException("将json字符串[json:{}]转换为对象[class:{}]时异常", json, clazz, e);
}
}
@@ -110,7 +110,7 @@ public abstract class JsonUtils {
try {
return MAPPER_TURBO.writeValueAsString(object);
} catch (Exception e) {
throw new RunException(e, "将对象[object:{}]转换为json字符串时异常", object);
throw new RunException("将对象[object:{}]转换为json字符串时异常", object, e);
}
}
@@ -119,7 +119,7 @@ public abstract class JsonUtils {
try {
return MAPPER.readValue(json, collectionType);
} catch (Exception e) {
throw new RunException(e, "将json字符串[json:{}]转换为List[{}]异常", json, clazz);
throw new RunException("将json字符串[json:{}]转换为List[{}]异常", json, clazz, e);
}
}
@@ -129,7 +129,7 @@ public abstract class JsonUtils {
try {
return MAPPER.readValue(json, collectionType);
} catch (Exception e) {
throw new RunException(e, "将json字符串[json:{}]转换为Set[{}]异常", json, clazz);
throw new RunException("将json字符串[json:{}]转换为Set[{}]异常", json, clazz, e);
}
}
@@ -138,7 +138,7 @@ public abstract class JsonUtils {
var ct = MAPPER.getTypeFactory().constructCollectionType(collectionType, elementType);
return MAPPER.readValue(json, ct);
} catch (IOException e) {
throw new RunException(e, "将json字符串[json:{}]转换为Collection[{}]异常", json, collectionType);
throw new RunException("将json字符串[json:{}]转换为Collection[{}]异常", json, collectionType, e);
}
}
@@ -147,7 +147,7 @@ public abstract class JsonUtils {
try {
return MAPPER.readValue(json, mapType);
} catch (Exception e) {
throw new RunException(e, "将json字符串[json:{}]转换为Map[[key:{}], [value:{}]]异常", json, kClazz, vClazz);
throw new RunException("将json字符串[json:{}]转换为Map[[key:{}], [value:{}]]异常", json, kClazz, vClazz, e);
}
}
@@ -156,7 +156,7 @@ public abstract class JsonUtils {
try {
return MAPPER.readValue(json, arrayType);
} catch (Exception e) {
throw new RunException(e, "将json字符串[{}]转换为数组[array:{}]异常", json, clazz);
throw new RunException("将json字符串[{}]转换为数组[array:{}]异常", json, clazz, e);
}
}
@@ -190,7 +190,7 @@ public abstract class JsonUtils {
}
}
} catch (IOException e) {
throw new RunException(e, "将json字符串[json:{}]转换为jsonTree[nodeName:{}]异常", json, nodeName);
throw new RunException("将json字符串[json:{}]转换为jsonTree[nodeName:{}]异常", json, nodeName, e);
}
return null;
}
@@ -216,7 +216,7 @@ public abstract class JsonUtils {
}
return jsonMap;
} catch (IOException e) {
throw new RunException(e, "将json字符串[json:{}]转换为jsonMap异常", json);
throw new RunException("将json字符串[json:{}]转换为jsonMap异常", json, e);
}
}
}