本文整理汇总了Java中com.mysql.jdbc.Util.stackTraceToString方法的典型用法代码示例。如果您正苦于以下问题:Java Util.stackTraceToString方法的具体用法?Java Util.stackTraceToString怎么用?Java Util.stackTraceToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mysql.jdbc.Util
的用法示例。
在下文中一共展示了Util.stackTraceToString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findCallingClassAndMethod
import com.mysql.jdbc.Util; //导入方法依赖的package包/类
public static String findCallingClassAndMethod(Throwable t) {
String stackTraceAsString = Util.stackTraceToString(t);
String callingClassAndMethod = CALLER_INFORMATION_NOT_AVAILABLE;
int endInternalMethods = stackTraceAsString.lastIndexOf("com.mysql.jdbc");
if (endInternalMethods != -1) {
int endOfLine = -1;
int compliancePackage = stackTraceAsString.indexOf("com.mysql.jdbc.compliance", endInternalMethods);
if (compliancePackage != -1) {
endOfLine = compliancePackage - LINE_SEPARATOR_LENGTH;
} else {
endOfLine = stackTraceAsString.indexOf(LINE_SEPARATOR, endInternalMethods);
}
if (endOfLine != -1) {
int nextEndOfLine = stackTraceAsString.indexOf(LINE_SEPARATOR, endOfLine + LINE_SEPARATOR_LENGTH);
if (nextEndOfLine != -1) {
callingClassAndMethod = stackTraceAsString.substring(endOfLine + LINE_SEPARATOR_LENGTH, nextEndOfLine);
} else {
callingClassAndMethod = stackTraceAsString.substring(endOfLine + LINE_SEPARATOR_LENGTH);
}
}
}
if (!callingClassAndMethod.startsWith("\tat ") && !callingClassAndMethod.startsWith("at ")) {
return "at " + callingClassAndMethod;
}
return callingClassAndMethod;
}
示例2: expandProfilerEventIfNecessary
import com.mysql.jdbc.Util; //导入方法依赖的package包/类
public static Object expandProfilerEventIfNecessary(Object possibleProfilerEvent) {
if (possibleProfilerEvent instanceof ProfilerEvent) {
StringBuilder msgBuf = new StringBuilder();
ProfilerEvent evt = (ProfilerEvent) possibleProfilerEvent;
String locationInformation = evt.getEventCreationPointAsString();
if (locationInformation == null) {
locationInformation = Util.stackTraceToString(new Throwable());
}
msgBuf.append("Profiler Event: [");
switch (evt.getEventType()) {
case ProfilerEvent.TYPE_EXECUTE:
msgBuf.append("EXECUTE");
break;
case ProfilerEvent.TYPE_FETCH:
msgBuf.append("FETCH");
break;
case ProfilerEvent.TYPE_OBJECT_CREATION:
msgBuf.append("CONSTRUCT");
break;
case ProfilerEvent.TYPE_PREPARE:
msgBuf.append("PREPARE");
break;
case ProfilerEvent.TYPE_QUERY:
msgBuf.append("QUERY");
break;
case ProfilerEvent.TYPE_WARN:
msgBuf.append("WARN");
break;
case ProfilerEvent.TYPE_SLOW_QUERY:
msgBuf.append("SLOW QUERY");
break;
default:
msgBuf.append("UNKNOWN");
}
msgBuf.append("] ");
msgBuf.append(locationInformation);
msgBuf.append(" duration: ");
msgBuf.append(evt.getEventDuration());
msgBuf.append(" ");
msgBuf.append(evt.getDurationUnits());
msgBuf.append(", connection-id: ");
msgBuf.append(evt.getConnectionId());
msgBuf.append(", statement-id: ");
msgBuf.append(evt.getStatementId());
msgBuf.append(", resultset-id: ");
msgBuf.append(evt.getResultSetId());
String evtMessage = evt.getMessage();
if (evtMessage != null) {
msgBuf.append(", message: ");
msgBuf.append(evtMessage);
}
return msgBuf;
}
return possibleProfilerEvent;
}